Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unhandled Rejection in Twilio SDK When Catching Exceptions in Application #949

Closed
mimu0 opened this issue Jul 20, 2023 · 8 comments
Closed
Assignees
Labels
status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library

Comments

@mimu0
Copy link

mimu0 commented Jul 20, 2023

Issue Summary

Twilio SDK has unhandled rejection in SDK and can't catch it from the application. This issue causes application termination.

Steps to Reproduce

  1. See the code snippet

Code Snippet

const client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);
const getMessages = async () => {
  try {
    const result =  await client.conversations.v1.services('SERVICE_SID').conversations('NOT_EXISTING_CONVERSATION_SID').messages.list();
    return result;
  } catch (e) {
    console.log('------catch from getMessages', e);
  }
};

process.on('unhandledRejection', (reason, promise) => {
  // this should not be called since we catch every exception
  console.log('------unhandledRejection', reason, promise);
});
process.on('rejectionHandled', (promise) => {
  console.log('------rejectionHandled', promise);

});

getMessages().then((messages) => {
  console.log('------messages', messages);
}).catch((e) => {
  console.log('------catch from caller', e);
});

Exception/Log

------catch from getMessages RestException [Error]: The requested resource /Services/ISe0ef118171da46b9bd8ef1d33c82349e/Conversations/CHc8c5b974343a4546bb022e511885b6f1/Messages was not found
    at MessagePage.processResponse (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/base/Page.js:135:19)
    at new Page (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/base/Page.js:17:28)
    at new MessagePage (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/rest/conversations/v1/service/conversation/message.js:315:9)
    at /Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/rest/conversations/v1/service/conversation/message.js:282:63
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 404,
  code: 20404,
  moreInfo: 'https://www.twilio.com/docs/errors/20404',
  details: undefined
}
------messages undefined
------unhandledRejection RestException [Error]: The requested resource /Services/ISe0ef118171da46b9bd8ef1d33c82349e/Conversations/CHc8c5b974343a4546bb022e511885b6f1/Messages was not found
    at MessagePage.processResponse (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/base/Page.js:135:19)
    at new Page (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/base/Page.js:17:28)
    at new MessagePage (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/rest/conversations/v1/service/conversation/message.js:315:9)
    at /Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/rest/conversations/v1/service/conversation/message.js:282:63
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  status: 404,
  code: 20404,
  moreInfo: 'https://www.twilio.com/docs/errors/20404',
  details: undefined
} Promise {
  <rejected> RestException [Error]: The requested resource /Services/ISe0ef118171da46b9bd8ef1d33c82349e/Conversations/CHc8c5b974343a4546bb022e511885b6f1/Messages was not found
      at MessagePage.processResponse (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/base/Page.js:135:19)
      at new Page (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/base/Page.js:17:28)
      at new MessagePage (/Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/rest/conversations/v1/service/conversation/message.js:315:9)
      at /Users/mimu/dev/summer-health/tmp/scripts/node_modules/twilio/lib/rest/conversations/v1/service/conversation/message.js:282:63
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
    status: 404,
    code: 20404,
    moreInfo: 'https://www.twilio.com/docs/errors/20404',
    details: undefined
  }
}

Technical details:

  • twilio-node version: 4.14.0
  • node version: 18.14.1
@jbzd
Copy link

jbzd commented Jul 28, 2023

We are experiencing this issue as well on the same library and node versions. Please advise - this is causing significant issues in our application.

@sbansla sbansla added status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library labels Jul 31, 2023
@sbansla
Copy link
Contributor

sbansla commented Aug 1, 2023

I am able to reproduce this issue.

@sbansla
Copy link
Contributor

sbansla commented Aug 2, 2023

Internal ticket has been created, we are working actively working on it.

@sbansla
Copy link
Contributor

sbansla commented Aug 2, 2023

https://github.com/twilio/twilio-node/blob/main/src/rest/conversations/v1/service/conversation/message.ts#L837
Above code snippet have not handled exception raised from:
https://github.com/twilio/twilio-node/blob/main/src/base/Page.ts#L226

--- We are checking our generator code, can this issue occur for all apis.

@dbburgess
Copy link

dbburgess commented Aug 8, 2023

I can confirm this also happens for me with other APIs. Saw hundreds of these today, unfortunately:

There was an uncaught error: The requested resource /2010-04-01/Accounts/[redacted]/Calls/[redacted]/Events.json was not found

The code for this is simply:

try {
  const currentCall = await twilioClient.calls(CallSid).fetch();
  const currentCallEvents = await currentCall.events().list();
  // ...trimmed for brevity...
} catch (error) {
  logger.error("Error fetching call events", error);
}

@sbansla sbansla mentioned this issue Aug 9, 2023
8 tasks
@sbansla sbansla self-assigned this Aug 9, 2023
@sbansla
Copy link
Contributor

sbansla commented Aug 10, 2023

Hi @dbburgess,
Fix has been released, let us know if this works for you.

@dbburgess
Copy link

@sbansla Thank you, I'll upgrade and test it out.

CC: @mimu0 @jbzd

@tiwarishubham635
Copy link
Contributor

Closing this issue as no feedback was received in last 30 days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: work in progress Twilio or the community is in the process of implementing type: bug bug in the library
Projects
None yet
Development

No branches or pull requests

5 participants