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

Throw a named error instead of a generic error, when no auth token is provided #222

Open
abdatta opened this issue Nov 22, 2020 · 1 comment

Comments

@abdatta
Copy link

abdatta commented Nov 22, 2020

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.

return self.fail(new Error("No auth token"));

So I request to define an error class for it like this:

class NoAuthTokenError extends Error {
    message = 'No auth token';
}

and then throw that instead

return self.fail(new NoAuthTokenError()); 

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.

@Outternet
Copy link

Outternet commented Sep 9, 2022

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)

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

No branches or pull requests

2 participants