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.

Comments

  • Steve, I could be wrong but if your code snippet was copied from your stored procedure I think the problem is that you have the wrong service. Instead of GetResponseStatusCode try GetResponseStatus.
  • I am using GetResponseStatusCode I chose it from the documentation under HTTPClient_Services. I do not see GetResponseStatus there. However when I use the SRP help (shift-f1) on GetResponseStatus it tells me that it returns the status of the most recent HTTP request. But then so does the documentation for GetResponseStatusCode. I must not understand something here.

    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.
  • Update - I added the HTTP_Services request to my code and forced an error in my request to AvaTax. It returned 200 yet the code in my example returned a 500 and the error body. When I used a bad URL the request timed out and I got nothing back from the HTTPClient_Services and the HTTP_Services still returned 200. It should be noted that I did nothing but stick in the following line of code.

    Result = Httpclient_Services("SendHTTPRequest", "POST", GetTaxURL, '', GetTaxPayload)
    Body = Httpclient_Services('GetResponseBody')
    Body2 = Http_Services('GetResponseStatus')
    StatusCode = Httpclient_Services('GetResponseStatusCode')

  • First, I must apologize for giving you a reply that ultimately sent you on a wild goose chase. I was rushing my answer since I was heading out the door for a few hours. You nearly identified my error on your own. I was looking at HTTP_Services when I should have been looking at HTTPClient_Services. HTTP_Services is strictly for when OI is being called as an HTTP server. In your case, you are using OI has an HTTP client. So, GetResponseStatusCode *is* the correct service. Again, sorry for the confusion I created there.

    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.
  • No apologies necessary. You have assisted so many times an occasional fumble is forgiven. But this getting older stuff does sneak up on one.

    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?
  • edited March 2017
    Okay, so I should expect something back on a time out or bad gateway etc. correct? Certainly the browser figures out something happens.
    Remember, the key issue here is "what the server returns" not "what the browser shows". The browser will show you many things because it is programmed to respond to all sorts of scenarios. The GetHTTPResponseCode service specifically checks for an HTTP Response code and only a running web server will return this. So if the web server returns nothing then the service will return nothing as well. Does that make sense?
    When the timeout triggers shouldn't I expect to find a 504 in the response code?
    Again, if the web server itself timed out and returned a 504 error, then this is what you should see. If something else timed out then it is likely you won't see anything.
    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.
    When you say you are "getting errors", what does that mean exactly? Are you seeing error messages of any kind from any source? Or are you simply saying the HTTP request isn't working and this is an "error" in and of itself?
    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?
    Not correct. The ERR_INTERNET_DISCONNECTED error is not an HTTP response. You might be able to check Error_Services for an error that was returned by the XMLHTTP object. As you can see, we update the internal error like so:

    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)
  • Okay, lets simplify this. Perhaps my approach is all wrong. Let's start with an intentionally bad URL. It simply does not exist. So I do the following
    1. 1. Result = HTTPClient_Services('SetTimeoutDuration', 10)
    2. 2. Result = Httpclient_Services("SendHTTPRequest", "POST", BADURL, '', GetTaxPayload)
    3. 3. Errors = Error_Services("GetMessages")
    4. 4. Body = Httpclient_Services('GetResponseBody')
    5. 5. StatusCode = Httpclient_Services('GetResponseStatusCode')
    6. 6. StatusPhrase = Httpclient_Services('GetResponseStatusPhrase')

    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.
  • Hmmm HttpClient_Services has the same $Insert Service_Setup and that issues an Error_Services("CLEAR") which then clears the common and my call after control is returned to me finds no errors.

    I think that points at the Service_Setup?
  • edited March 2017
    Ah...the problems of using different versions of the product. I think we fixed the problem you are running into with a later release. I can only look at and test the current version that I have installed. You are correct, there is a point where the errors are cleared so we have this code near the bottom of the SendHTTPRequest service:

    // 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.
Sign In or Register to comment.