Hi, I have a requirement where I want to catch only the No auth token errors on authentication failure.
Right now I have to check exactly the message property like this: err.message === 'No auth token'.
However, I'm afraid any future change in the error message might break my app.
This is a good point, either error classes (wich is against the offical passport documentation) or error messages should be put in an enum. Please add a PR (if you can directly to the rewrite)
Hi, I have a requirement where I want to catch only the
No auth token
errors on authentication failure. Right now I have to check exactly themessage
property like this:err.message === 'No auth token'
. However, I'm afraid any future change in the error message might break my app.https://github.com/mikenicholson/passport-jwt/blob/96a6e5565ba5a6f3301d91959a0f646e54446388/lib/strategy.js#L96
So I request to define an error class for it like this:
and then throw that instead
This helps me to check the error using:
err instanceof NoAuthTokenError
, and any future change to the error message won't cause any breaking change.Lemme know if this sounds reasonable. I'll create a PR for the same then.