express-oauth-server icon indicating copy to clipboard operation
express-oauth-server copied to clipboard

Change handleError to throw or call next if not OAuthError

Open chainlink opened this issue 8 years ago • 1 comments

If the error encountered is not expected (ie. not an OAuth Library error) it should re throw the error (or at least pass it to next to be dealt with)

https://github.com/oauthjs/express-oauth-server/blob/master/index.js#L142

I propose checking if it's an instance of https://github.com/oauthjs/node-oauth2-server/blob/master/lib/errors/oauth-error.js

If you agree I can prepare a PR

chainlink avatar Nov 09 '16 23:11 chainlink

None of the middlewares exported by OAuth2Server ever return an unknown error type. Unknown errors are always wrapped using ServerError (#authenticate, #authorize, #token).

With #19 merged you can initialize the server like this:

new OAuthServer({
  model: ...,
  useErrorHandler: true
});

which tells express-oauth-server to forward errors using next(err) instead of sending a response by itself.

maxtruxa avatar Nov 10 '16 13:11 maxtruxa