set_error_handler doesn't handle string rejections
See original GitHub issueNot sure if this is a bug or an expected limitation.
In express I use express-promise-router
to add this. Would be nice to see this built into hyper-express
.
const HyperExpress = require('hyper-express');
const webserver = new HyperExpress.Server();
// Works
webserver.get('/works', () => {
throw new Error('Hello World');
});
// Never responds
webserver.get('/not-working', async () => {
await new Promise((_resolve, reject) => {
return reject('Hello World');
});
});
// This is only called for the thrown error but not the rejection
webserver.set_error_handler((_request, _response, error) => {
console.log('error', error);
});
webserver.listen(80)
.then(() => console.log('Webserver started on port 80'))
.catch(() => console.log('Failed to start webserver on port 80'));
Issue Analytics
- State:
- Created a year ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Catch all unhandled javascript promise rejections
uncaught library can help you to catch unhandled promise rejections. And it handles uncaught errors as well. EDIT
Read more >Best Practices for Node.js Error-handling - Toptal
Developers working with Node.js sometimes find themselves writing not-so-clean code while handling all sorts of errors. This article will introduce you to ...
Read more >schema validation error on an async response does not ...
When using response schema validation on a route with an async handler errors are not caught by the error handler set using setErrorHandler...
Read more >A mostly complete guide to error handling in JavaScript.
Learn how to deal with errors and exceptions in synchronous and asynchronous JavaScript code. ... message : a string with the error message....
Read more >Better Error Handling In NodeJS With Error Classes
You can get by in NodeJS without properly handling errors but due to ... as it is either resolved or rejected it cannot...
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
Thank you so much, this works perfectly. 🥳
This issue has been fixed in the recently released
v6.2.4
of HyperExpress. Let me know If you encounter any other issues.