Solved

Looping on Error in ASP Classic

Posted on 2013-01-24
2
406 Views
Last Modified: 2013-01-24
I am using a function to do a call to an external API.  The problem is sometimes the API denies the request leaving me with an ASP error.

I am wondering what the best solution would be to include error handling inside the function itself that would retry the function 5 times before giving up and doing a response.end.

Example of the function code
Function API(apiname,apistring)
	Set oHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
	oHttp.settimeouts 100000,100000,100000,100000	
	oHttp.setoption(2) = 13056
	oHttp.open "GET", apiurl & apiname & "?" & apistring, false
	oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	oHttp.send apistring
	fAPI = trim(oHttp.ResponseText)
	set oHttp = nothing
End Function

Open in new window

0
Comment
Question by:ScotTFO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 38815135
this should do:
Function API(apiname,apistring, retries)
  on error resume next 
	Set oHttp = Server.CreateObject("Msxml2.ServerXMLHTTP")
	oHttp.settimeouts 100000,100000,100000,100000	
	oHttp.setoption(2) = 13056
	oHttp.open "GET", apiurl & apiname & "?" & apistring, false
	oHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
	oHttp.send apistring
        if err.number = 0 then
	   fAPI = trim(oHttp.ResponseText)
        else
           if retries <= 0 then
              fAPI = err.description
           else
              fAPI = API(appiname, apistring, retries -1)
           end if
        end if
	set oHttp = nothing
   API = fAPI
End Function

Open in new window


and you call it with a third argument, the number of retries
0
 

Author Closing Comment

by:ScotTFO
ID: 38815186
This is exactly what I needed.  I didn't think about passing retry with the function.  This made it very simple.

Thank you very much.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question