graphql-dotnet: Expanding documentation with error handling examples
The documentation is not very clear with regards to how to:
- Create custom errors
- Throw these custom errors
- Customize the rendering of these errors to JSON (for example how to add fields to the
errorsresponse object)
Is there any example out there that showcases these?
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 1
- Comments: 19 (12 by maintainers)
@joemcbride Maybe I am fundamentally miss understanding async/await or the middleware. I tried that before and the catch block never gets executed.
I do agree, that would be the best case scenario for translating domain exceptiong as a cross-cutting concern.
I made a similar detour and couldn’t get it to work nicely without forking the project. For this current project I decided that our domain exceptions just inherit from
ExecutionError.I only had one idea left which I didn’t explore yet. In the GraphQL Middleware there might be a spot where I could translate domain exceptions in to
ExecutionErrors.As for your resolver structure. I used a mediator pattern with some rather large abstractions. My resolvers are only sending a message object with some props and the mediator is invoking the correct handler. That way my logic is agnostic of GraphQL (aside from the domain exceptions)