Home Forums Integration Integration (Code) How to handle HTTP Status Codes

Viewing 1 reply thread
  • Author
    Posts
    • #12157
      Mohammad IkmailMohammad Ikmail
      Participant

      Hello,

      We have an API that will return different HTTP status codes:

      • Success Code (2xx)
        • In this case response body will be empty.
      • Client Errors (4xx)
        • In this case response body will have a JSON with the actual error from the other system.

      the problem is integration-send-receive¬†will throw an exception if status code is 4xx and we can’t access the response body.

      (set! resp (integration-send-receive httpMsg channelToSend ()))

      please suggest how we can get the response if the status code is 4xx.

      Thanks

       

      0
    • #12177
      Ed ShawEd Shaw
      Keymaster

      Hi,

      Have a look at the HTTP channel ‘error’ property. It can be used so you can handle non-200 statuses yourself.

      The error property is an expression returning non-#f if the message should be treated as an error.

      This property is used to specify special cases that you want to handle yourself. By default anything other than a status of 200 will be treated as an error. By setting this to something different, you can handle the exceptions yourself. If you handle the message yourself, the raw message is passed into your service as “this”.

      Example

      ; accept responses with status code of OK (200) or Redirection (302) – reject all others
      (not (in? (this’status) ‘(200 302)))

      To handle 400 or 500 errors, just add them to the list.

      Documentation on HTTP channels can be found at https://community.nexj.com/documentation/reference/modl/latest/http.html.

      Cheers,

      Ed

      0
Viewing 1 reply thread
  • You must be logged in to reply to this topic.