Describe the bug
Trying to call the api through the node client lib, (E.g.: /events using the library (const events = await connection.events.list({...}))) when api.nylas.com cannot be (DNS) resolved (e.g.: client machine is offline), the error is not propagated to the caller, but a the following warning is printed to the console (node v12.22.1):
(node:126491) UnhandledPromiseRejectionWarning: FetchError: request to https://api.nylas.com/events?starts_before=1635335950&ends_after=1628076547&expand_recurring=true&calendar_id=<calendar id>&offset=0&limit=100 failed, reason: getaddrinfo EAI_AGAIN api.nylas.com
at ClientRequest.<anonymous> (/home/<project>/<repo>/node_modules/node-fetch/lib/index.js:1461:11)
at ClientRequest.emit (events.js:314:20)
at TLSSocket.socketErrorListener (_http_client.js:427:9)
at TLSSocket.emit (events.js:314:20)
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:84:21)
(node:126491) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:126491) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
To Reproduce
Run the below code after you made sure that your machine has no internet connection
const client = Nylas.config({clientId: 'xxx', clientSecret: 'xxxx'});
const connection = client.with('user account token');
const events = await connection.events.list({...});
Expected behavior
An error should be raised on the caller thread
SDK Version:
5.6.0
Additional context
Debugging/modifying the source code, I believe the the fix could be modifying https://github.com/nylas/nylas-nodejs/blob/main/src/nylas-connection.ts#L200 (checked the latest version at the time,
|
return fetch(req).then(response => { |
)
Current implementation:
200 request(options: RequestOptions) {
...
203 return fetch(req).then(response => {
...
259 });
To fix the reported issue, this should have a catch block added to it, i.e.:
259 }).catch((error) => {
reject(error); // or add some custom error message
}
Describe the bug
Trying to call the api through the node client lib, (E.g.:
/eventsusing the library (const events = await connection.events.list({...}))) whenapi.nylas.comcannot be (DNS) resolved (e.g.: client machine is offline), the error is not propagated to the caller, but a the following warning is printed to the console (node v12.22.1):To Reproduce
Run the below code after you made sure that your machine has no internet connection
Expected behavior
An error should be raised on the caller thread
SDK Version:
5.6.0Additional context
Debugging/modifying the source code, I believe the the fix could be modifying https://github.com/nylas/nylas-nodejs/blob/main/src/nylas-connection.ts#L200 (checked the latest version at the time,
nylas-nodejs/src/nylas-connection.ts
Line 203 in 270f865
Current implementation:
To fix the reported issue, this should have a catch block added to it, i.e.: