intercom-node
intercom-node copied to clipboard
Do not throw undefined when the response body does not match the intercom API format
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
- set baseURL to a local HTTP server that responds with a >=400 status code:
client.useRequestOpts({
baseURL: 'http://local.test-server.com',
});
- Launch a request via intercom client, e will be undefined
try {
await intercom.ping();
} catch (e) {
console.error(e);
}