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

How to pass variables into the error message. #66

Open
santanuyogi opened this issue Apr 16, 2020 · 2 comments
Open

How to pass variables into the error message. #66

santanuyogi opened this issue Apr 16, 2020 · 2 comments

Comments

@santanuyogi
Copy link

This is more of a question than it is an issue. Is there any way to pass a variable into the error message?

If I have the following error message:

throw new Error(
  `There was no user found with the username, ${username}.`
);

How can I get that username into the apollo-errors? Is there a way to pass it as an argument?

throw new err.IncorrectUsernameError(username);

Inside my error file that imports apollo-errors:

exports.IncorrectUsernameError = createError('IncorrectPasswordError', {
  message: `There was no user found with the username, ${username}.`,
});

Please let me know if there is some way to accomplish this.

@whitte-h
Copy link

Hi, just found this library, but I think you could achieve that behavior using a HOC to wrap the error creation, that way you could send a custom message, maybe it's too late for the reply but someone might find it useful

@whitte-h
Copy link

Also, you could just overload the message as it's in the docs

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