?
Solved

Looping on Error in ASP Classic

Posted on 2013-01-24
2
Medium Priority
?
417 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 2000 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

I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
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/…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

770 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