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

Middleware Error handling incomplete #134

Open
kinsi55 opened this issue Apr 26, 2020 · 1 comment
Open

Middleware Error handling incomplete #134

kinsi55 opened this issue Apr 26, 2020 · 1 comment
Labels

Comments

@kinsi55
Copy link

kinsi55 commented Apr 26, 2020

As I saw in previous issues, v1 (Apparently) is supposed to catch errors thrown by middleware, however the current implementation wont be good enough for that.

In the examples, one is the first and two is a second middleware

Example handled by the current implementation:

function one(req, res, next) {
	next();
}
function two(req, res, next) {
	throw new Error("test");
}

Modified version that will not get caught:

function one(req, res, next) {
	setImmediate(next);
}
function two(req, res, next) {
	throw new Error("test");
}

As you can see, once a middleware finished in an async fashion, errors thrown by any middleware ran after it will not get caught, the reason for that is because the try/catch block will obviously be exit' since its an async operation.

To properly resolve this one would need to have the try/catch be within the wrapper loop() method.

@astahmer
Copy link

Any update on this ? It feels awkward not being able to throw from a middleware

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants