Error thrown inside an async rule are not sent to the fallbackError function
See original GitHub issueDescribe the bug
If an async rule throws inside a chain, the error is not sent to the fallbackError
function. The value is null.
Example
const editorIsEventOwner= chain(
isPromoterStaff,
rule({ cache: PermissionCache.STRICT })(
async (_parent: {}, args: { id: string }, ctx: Context) => {
const { id } = args;
const event = await findEvent(toInt(id), ctx); // This can throw an Error
if (!event) return false;
return event.ownerId === ctx.user?.id;
}
)
);
This will correctly not allow the user to proceed if the findEvent
fails, but it will not put the Error
in the first parameter of the the function.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:7
- Comments:16 (6 by maintainers)
Top Results From Across the Web
Error thrown inside an async rule are not sent to the ... - GitHub
Describe the bug If an async rule throws inside a chain, the error is not sent to the fallbackError function. The value is...
Read more >How to Throw Errors From Async Functions in JavaScript?
Throwing errors is a best practice for dealing with unknowns. The same rule applies for every modern language: Java, JavaScript, Python, Ruby.
Read more >Errors – GraphQL Shield
Shield, by default, catches all errors thrown during resolver execution. ... Rules that return error are treated as failing, therefore not ...
Read more >Can I throw error in an async function? - Stack Overflow
But I'm using async function, so no res and rej methods are there. So, the question: can I throw errors in async functions?...
Read more >Common Mistakes in JavaScript Async Function Error Handling
Learn JavaScript Async Function Error Handling, and don't throw an error like a normal synchronous function. Error handling is important in JavaScript flow ......
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
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I created a wrapper for the rule function. I would be willing to rewrite part of the lib to support more native feature if @maticzav let me. I basically did it with nexus-shield. I think the shift to
throw
would be better.