Open Miggets7 opened 1 month ago
Authorization header is a part of the http request header, make sure you are getting it from request headers in your middleware function. Also make sure that you have sent the auth token(base64-encoded) to the server with a subsequent request. I mean you must check that authorization header is present in your http request header.
const authorization = request.headers.authorization
Also I suggest you to use next()
instead of return next()
since it is a middleware function. Also make sure that you are correctly extracting the token from the authorization headers. It is very hard to guess the exact error because we can not reproduce the exact error at our end. Therefore follow above checks and reproduce the exact error.
It's not about extracting the token. It's about throwing an Error instead of using next(Error)
. It's seems throwing causes the app to crash whereas using next(Error)
doesn't. But both still reach the global error handler.
It's not about extracting the token. It's about throwing an Error instead of using
next(Error)
. It's seems throwing causes the app to crash whereas usingnext(Error)
doesn't. But both still reach the global error handler.
If both throwing and next(Error) trigger the global error handler then what is the issue?
Also, by app crashing do you mean one of your snippets above somehow misses the global error handler and crashes the program due to an uncaught exception?
What I mean is throwing causes the crash. So the program exits.
When using Next(error)
the program doesn't crash, so it doesn't exit.
Hey, I am looking into this now. It seems that the error may be escaping the global handler when not explicitly passed to Next
while this should not be the case, it is likely a bug.
I've got this middleware function:
And this error handler:
The error handler code is called, but still the application crashes:
It however doesn't crash when writing the middleware like this:
Is this intended to use
return next(error)
or is it a bug?