Impossible to handle your errors on my API
See original GitHub issueHi! I’m using your module on my API and it’s run perfectly using my oauth2 generated tokens! However, when the token has expired I’m having issues catching the exception.
So this is a problem, because my application crashes due this fail instead of notifying the user their token has expired. How to fix and catch this problem?
This is my try/catch error.
var Gmail = require('node-gmail-api')
var userKey = 'INVALID USER TOKEN HERE'
try {
var gmail = new Gmail(userKey)
var s = gmail.messages('label:inbox', { max: 10 })
s.on('data', function (d) {
console.log(d.snippet)
})
}
catch(e) {
console.log('Your credentials are wrong')
return 0;
}
So when the token is not valid I have reported this issue:
events.js:160
throw er; // Unhandled 'error' event
^
Error: Invalid Credentials
at Request._callback (/node_modules/node-gmail-api/index.js:84:37)
at Request.self.callback (/node_modules/request/request.js:186:22)
at emitTwo (events.js:106:13)
at Request.emit (events.js:191:7)
at Request.<anonymous> (/node_modules/request/request.js:1081:10)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at IncomingMessage.<anonymous> (/node_modules/request/request.js:1001:12)
at IncomingMessage.g (events.js:291:16)
at emitNone (events.js:91:20)
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Best Practices for REST API Error Handling - Baeldung
The simplest way we handle errors is to respond with an appropriate status code. Here are some common response codes: ... While basic,...
Read more >Best practices for API error handling and troubleshooting
On server side, Orange APIs handle errors by aborting the request and immediately returning an error response to your application.
Read more >Best Practices for API Error Handling - Nordic APIs
As we've already said, error codes are extremely useful. Error codes in the response stage of an API is the fundamental way in...
Read more >Error Handling and Troubleshooting with API - YouTube
An important element of any software application is concise, useful error handling. Error handling refers to the anticipation, detection, ...
Read more >Graceful error handling in REST-driven web applications
An API client should be able to react accordingly to various types of errors, I would therefore advise that you implement your error...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I reply myself to message of Dec 12, 2016 about handling this error. I found a really great stack overflow post that teaches how to handle different errors depending on code implementation and the way new errors are generated.
Best practice for exception handling
So! According to this post (and of course I’ve tried it out), we have to listen for errors before doing any other operation, like the following code (this code is extracted from a real project i’m working on):
👍