Allow for registering global mutation convention exceptions mapped to a single error type #5857
glen-84
started this conversation in
Feature Request
Replies: 2 comments
-
I do not think that we will implement this. I have quite strong feelings against this. I might change my stance on this. I am moving this to discussions and we can revisit it in the future. |
Beta Was this translation helpful? Give feedback.
0 replies
-
I have two use cases here:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Product
Hot Chocolate
Is your feature request related to a problem?
Handling common exceptions requires you to apply attributes to many mutations, even if you don't require more specific error properties.
The solution you'd like
What if you could register one or more exceptions that map to the same "generic" error type?
For example:
When an exception occurs, it will be handled by
Error
attributes on the mutation first. If there is no matching error attribute, and the exception implementsIError
, then a generic error type will be returned based on the error interface.In this way, you're not adding
DomainError
andNotFoundError
to many mutations or every mutation, but rather a singleError
type is created for handling the registered "global exceptions".So instead of using:
You could just have:
If your error interface contains a
Message
and aCode
, then you can do the following on any mutation:Having
DomainException
andNotFoundException
extend a common base exception would still require you to add that error to every single mutation in your schema, so that doesn't solve the problem.I'm aware of certain best practices like strongly-typed errors, and alternatives like result objects, but they're not always feasible, and don't always make sense.
Note that this doesn't solve the issue of libraries being able to add application-level errors that don't result in HTTP 500 results. If it were possible to raise an application-level error using middleware, for example, then that same mechanism could potentially be used to achieve something similar to the above suggestion.
Beta Was this translation helpful? Give feedback.
All reactions