intercom-node icon indicating copy to clipboard operation
intercom-node copied to clipboard

Do not throw undefined when the response body does not match the intercom API format

Open BogdanCln opened this issue 1 year ago • 0 comments

Version info

  • intercom-node version: 4.0.0
  • Node version: 18

Expected behavior

We are using an HTTP proxy for all the outbound requests. If the proxy cannot establish the HTTP tunnel to api.intercom.com, we expect an exception that is easy to debug.

Actual behavior

undefined is thrown when an error that is not parsable is encountered; in our case: when the proxy server cannot reach intercom API. The Client.checkOnErrorInResponse() returns undefined when the error does not have the intercom API format. In this case, I think that setting the response body as an error message (instead of undefined) would be a nice improvement.

Steps to reproduce

  1. set baseURL to a local HTTP server that responds with a >=400 status code:
client.useRequestOpts({
    baseURL: 'http://local.test-server.com',
});
  1. Launch a request via intercom client, e will be undefined
try {
    await intercom.ping();
} catch (e) {
    console.error(e);
}

BogdanCln avatar Oct 03 '23 13:10 BogdanCln