Solved

Looping on Error in ASP Classic

Posted on 2013-01-24
2
403 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 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML Parsing Classic ASP 5 64
Scheduled IIS .Net2 AppPools recycle and SQL connection Hangs 33 125
Time Conversions...both ways 2 16
ASP/VB email question 4 46
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/…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

791 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