Custom errors for rules and global fallback
See original GitHub issueHi @maticzav! First of all thanks for the awesome library!
I have few questions/suggestions about CustomErrors:
- Is there a way to specify CustomError that will be returned from shield in case if permissions checks are failed?
Example: I have isAuthenticated rule
export default rule()((parent, args, { user }) => Boolean(user));
I want to return my custom 401 error like this
import { SevenBoom } from 'graphql-apollo-errors';
rule(null, {
customError: SevenBoom.unauthorized('You are not authenticated')
})((parent, args, { user }) => Boolean(user))
- Is there a way to specify global CustomError instead of https://github.com/maticzav/graphql-shield/blob/master/src/index.ts#L234 which will be used in case if there is no rule specific error?
Example:
import { SevenBoom } from 'graphql-apollo-errors';
shield({ /* Rules… */ }, {
customError: SevenBoom.forbidden('You are not allowed to do this action.')
})
I can implement this and looks like it is not a breaking change.
Just want to clarify if there is no way to do this in current version of the library?
Let me know if you have any questions. Thanks!
Issue Analytics
- State:
- Created 5 years ago
- Comments:23 (11 by maintainers)
Top Results From Across the Web
Custom errors for rules and global fallback · Issue #60 - GitHub
To conclude, I propose to change the functionality by adding customError or error function which is returned from the rule in case of...
Read more >Errors – GraphQL Shield
Custom Errors. Shield, by default, catches all errors thrown during resolver execution. This way we can be 100% sure none of your internal...
Read more >Error Messages - VeeValidate
By default, any unspecified rules for the specific field messages will fallback to the already included ones, so you only need to define...
Read more >Create Custom Error Response Rules | Imperva
A custom error response rule enables you to replace the default error response and error code that are returned to the client.
Read more >Handling Error Conditions Using a Step Functions State ...
Learn how to handle error conditions using an AWS Step Functions state machine. ... The context object returns the error message This is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is there no way to just map error messages to rules? That seems like the way to go.
I’m a few years late, but this seems to be a general problem with functions doing more than one thing. Rules should just test and return a boolean. That’s a separate concern from deciding which error to throw.