Welcome to the SRP Forum! Please refer to the SRP Forum FAQ post if you have any questions regarding how the forum works.
Trouble with some error processing using HTTPClient_Services
The following is used to post a request to AvaTax, a sales tax service API
Result = Httpclient_Services("SendHTTPRequest", "POST", GetTaxURL, '', GetTaxPayload)
Body = Httpclient_Services('GetResponseBody')
StatusCode = Httpclient_Services('GetResponseStatusCode')
debug
CombinedStatusCode = StatusCode
// Successful return
If StatusCode[1,1] EQ 2 Then
GoSub ProcessTaxDetail
End Else
...Error processing here.
If I have a bad URL or Bad Gateway or timeout, what status does SRP return? I have traps in place to catch 502 a bad gateway, 503 service unavailable, 504 gateway timeout and one for everything else. Yet I have not been able to trap any response status codes of anything but null. I realize that this maybe something I am missing completely. I would expect status code to be set to 502 etc. But the best I can tell so far is that there is nothing in the body or status code. I am looking for some suggestions on how to proceed.
Result = Httpclient_Services("SendHTTPRequest", "POST", GetTaxURL, '', GetTaxPayload)
Body = Httpclient_Services('GetResponseBody')
StatusCode = Httpclient_Services('GetResponseStatusCode')
debug
CombinedStatusCode = StatusCode
// Successful return
If StatusCode[1,1] EQ 2 Then
GoSub ProcessTaxDetail
End Else
...Error processing here.
If I have a bad URL or Bad Gateway or timeout, what status does SRP return? I have traps in place to catch 502 a bad gateway, 503 service unavailable, 504 gateway timeout and one for everything else. Yet I have not been able to trap any response status codes of anything but null. I realize that this maybe something I am missing completely. I would expect status code to be set to 502 etc. But the best I can tell so far is that there is nothing in the body or status code. I am looking for some suggestions on how to proceed.
Comments
A little more research and I see that HTTP_Services rather than HTTPClient_Services uses GetResponseStatus it is the latter I am using, perhaps incorrectly, and in that case the only option I had was the GetResponseStatusCode
One last detail, this particular code has been processing about 25-30 thousand transactions daily. I do get valid 200 series status codes okay and 500. Your explanation of what I may be doing wrong would be helpful.
Result = Httpclient_Services("SendHTTPRequest", "POST", GetTaxURL, '', GetTaxPayload)
Body = Httpclient_Services('GetResponseBody')
Body2 = Http_Services('GetResponseStatus')
StatusCode = Httpclient_Services('GetResponseStatusCode')
Now back to the issue at hand. The GetResponseStatusCode service only returns what the server returns via the XMLHTTP object. Nothing more and nothing less. I would imagine that if you entered a bad URL then you would likely get no response because there is no server to generate a response. This is no different than if you entered the same URL within a browser. You don't get an HTTP response status code. The other conditions, such as bad gateway or timeout should be no different. Whatever you would see in a browser in terms of a status code is what you should see being returned in this service.
Okay, so I should expect something back on a time out or bad gateway etc. correct? Certainly the browser figures out something happens. I see in testing here at desk that a bad address brings back a result that triggers a dns assist from my local internet provider. I cannot see which is getting to my browser. On the office desktop there is a message that indicates a bad DNS. I must be doing something wrong because I don't seem to find anything in the response code or anything else that I have learned to look for with HTTPClient_Services. Let's say the server at AvaTax is down. I use all the right addresses but eventually a timeout occurs. When the timeout triggers shouldn't I expect to find a 504 in the response code?
The reason for my attention to the detail here is that I am getting errors that have no response code. I can't pin down just what is happening. They are sporadic and that makes it really difficult to test. Can you suggest some pointers. At this point if I get anything but a response code starting with 2 I run off to a routine to print anything at all that I get back. So far most of the time I get nothing. If AvaTax is complaining I then get results that are pretty complete.
If I disconnect from the internet and try to get to the SRP home page I get back ERR_INTERNET_DISCONNECTED among some other things in my browser. I understand you to say that I should find something similar in what is returned to my HTTPClient_Services request. Correct?
Error = 'Error getting the responseBody property for the XMLHTTP object in the ' : Service : ' service.' Error := ' SRP_COM Error: ' : SRP_COM('', 'ERROR') Error_Services('Add', Error)
Since there is no web server to send anything back there will not be anything at all in what is returned from the HTTPClient_Services request. And that is correct. Everything is blank. I then call Error_Services("GetMessages") That returns nothing. Note that other than the SRP Service Setup Insert nothing is done to initialize or use Error_Services. So I am at a loss as to how to proceed. I put a debug into HttpClient_Services, turned on the display flag and indeed Error_Services is getting called and placing an error on the stack. But by the time control is returned to me and I execute Error_Services("GetMessages") there is nothing in the common used by Error_Services nor returned to me. Note that the insert for Service_Setup has a history update History : (Date, Initials, Notes)
08/13/10 dmb Original programmer. There is an Error_Services("CLEAR") within it. Other than that and my request for error status there are no other calls or references in my code to Error_Services. I stepped through all of this and there is another call from somewhere as control is returned from my line item #2 above.
Hope that didn't muddy the water.
I think that points at the Service_Setup?
// Make sure all prior request settings so future HTTP request won't be affected. Error = Error_Services('GetMessage') ; // Get any pre-existing errors so they can be preserved. HTTPClient_Services('ClearRequestSettings') ; // This will automatically clear the error stack. Error_Services('Set', Error) ; // Restore any errors so the caller can check for them.