question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

set_error_handler doesn't handle string rejections

See original GitHub issue

Not 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:closed
  • Created a year ago
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
ImLunaHeycommented, Jun 21, 2022

Thank you so much, this works perfectly. 🥳

1reaction
kartikk221commented, Jun 21, 2022

This issue has been fixed in the recently released v6.2.4 of HyperExpress. Let me know If you encounter any other issues.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found