addon.httpClient(req) not setting error on callback when request fails

I am sorry to bother. I am experiencing a weird issue. I am purposely making a failing call the the API. The body I am getting on the response is describing the error, but the err variable is never set on the callback, even though response has statusCode set to 400. The same call in postman returns 400 as well.

httpClient = addon.httpClient(req)
httpClient.put({ url, json: data },
  function (err, response, body) {
    console.log('err', err) // always null

Any idea why err is not being set?
Thank you!

@LeandroPelorosso I believe you’ll see err set when a request isn’t properly set/sent or response isn’t properly received… in other words, when there’s an issue at the http client level. Therefore, if you crafted a good request and received a response from the Jira Cloud instance, even if it is a 4xx error, the httpClient code won’t throw an error that fills err.

1 Like

Thank you! @nmansilla ! That makes sense.
Do you know if there is a recommended way of knowing if the response was successful or not? (like checking the body of the response for an errors key, or the statusCode of the response).
Thank you again!

@LeandroPelorosso I would check response.statusCode. If you get a 200 (or anything in the 2xx) then you’re :white_check_mark:. That being said, I’d check the API reference docs for list of possible response codes on the methods you’re calling.

1 Like

Thank you @nmansilla :slight_smile: