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

Customizing the error messages #51

Closed
shanmugarajbe opened this issue Jul 20, 2018 · 1 comment
Closed

Customizing the error messages #51

shanmugarajbe opened this issue Jul 20, 2018 · 1 comment

Comments

@shanmugarajbe
Copy link

I need to customize the error messages. For example, if a user with role of "Buyer" is trying to access my resource but grants object doesn't contain the role called "Buyer" and accesscontrol will throw "Role not found: \"Buyer\"". Here I want to take the control of error block either synchronously/asynchronously and customize the error message and send to the end point. Please provide if any one knows have done it previously.
Thanks

@onury
Copy link
Owner

onury commented Feb 7, 2019

The user does/should not define his/her own role.
You should pre-define the roles, resources, etc...
Then if you have the role Buyer added to the instance, it will not throw Role not found.
It will simply deny permission to that user (if not Buyer).

Apart from this; to answer your question,
You can catch and re-throw an error, or modify the message before sent/shown to user.

function risky() {
    throw new Error('NOT_FOUND');
}

try {
    risky();
} catch (e) {
    if (e.message === 'NOT_FOUND') {
        response('custom message');
    } else {
        throw e; // re-throw original
    }
}

@onury onury closed this as completed Feb 7, 2019
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