Solved

Looping on Error in ASP Classic

Posted on 2013-01-24
2
401 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
2 Comments
 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now