intercom / intercom-node

Node.js bindings for the Intercom API
https://developers.intercom.com
Other
362 stars 116 forks source link

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

Open BogdanCln opened 9 months ago

BogdanCln commented 9 months ago

Version info

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',
    });
  2. Launch a request via intercom client, e will be undefined
    try {
    await intercom.ping();
    } catch (e) {
    console.error(e);
    }