Skip to content

Pass error message#219

Merged
Tranced merged 6 commits intomainfrom
pass-error-message
Mar 25, 2021
Merged

Pass error message#219
Tranced merged 6 commits intomainfrom
pass-error-message

Conversation

@Tranced
Copy link
Copy Markdown
Contributor

@Tranced Tranced commented Mar 24, 2021

Just wanted to pass along the error message generically in our SDK if customers come upon them.
Looks like we only pass status code.

For context, a customer is using native auth and is only seeing a 401.
However, in our authentication example(which just uses a regular request/not the SDK), we're able to see the full stack trace.

Before, the message from the SDK was:

Error:
    at Request._callback (/home/oleg/Documents/bs/address-book/node_modules/nylas/lib/nylas-connection.js:140:33)
    at Request.self.callback (/home/oleg/Documents/bs/address-book/node_modules/request/request.js:185:22)
    at Request.emit (events.js:314:20)
    at Request.<anonymous> (/home/oleg/Documents/bs/address-book/node_modules/request/request.js:1154:10)
    at Request.emit (events.js:314:20)
    at IncomingMessage.<anonymous> (/home/oleg/Documents/bs/address-book/node_modules/request/request.js:1076:12)
    at Object.onceWrapper (events.js:420:28)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1241:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  statusCode: 401
}

now it's:

Error: Nylas_Error: You've entered invalid credentials.  Provider_Error: Wrong username or password for https://outlook.com/EWS/Exchange.asmx
    at Request._callback (/Users/terenceyang/nylas-nodejs/lib/nylas-connection.js:193:23)
    at Request.self.callback (/Users/terenceyang/nylas-nodejs/node_modules/request/request.js:185:22)
    at Request.emit (events.js:314:20)
    at Request.<anonymous> (/Users/terenceyang/nylas-nodejs/node_modules/request/request.js:1161:10)
    at Request.emit (events.js:314:20)
    at IncomingMessage.<anonymous> (/Users/terenceyang/nylas-nodejs/node_modules/request/request.js:1083:12)
    at Object.onceWrapper (events.js:420:28)
    at IncomingMessage.emit (events.js:326:22)
    at endReadableNT (_stream_readable.js:1226:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  statusCode: 401
}

License

I confirm that this contribution is made under the terms of the MIT license and that I have the authority necessary to make this contribution on behalf of its copyright owner.

Comment thread src/nylas-connection.js Outdated
}
if (response.statusCode) {
error.statusCode = response.statusCode;
if (!error.hasOwnProperty('message')) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Tranced, I think we may want to also check typeof response.body === 'string' to make sure we're returning a string. It's also worth considering adding an else clause in case response.body isn't a string, and just responding with a generic error message.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me! I'm not sure what cases we'll run into if the error message is not a string. So, in that case, I'll just leave it with the current default behavior.

Copy link
Copy Markdown

@ozsivanov ozsivanov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Tranced Tranced merged commit 7125486 into main Mar 25, 2021
@Tranced Tranced deleted the pass-error-message branch March 25, 2021 18:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants