Solved

Looping on Error in ASP Classic

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
JQuery Date Time picker not showing 29 95
Issue with Loop 4 43
classic asp checkbox uncheck and check 2 49
JSON error 4 38
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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

746 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

11 Experts available now in Live!

Get 1:1 Help Now