smallrye / smallrye-graphql

Implementation for MicroProfile GraphQL
Apache License 2.0
160 stars 91 forks source link

Add generic ability to add extension key-value for Errors #299

Closed phillip-kruger closed 2 years ago

phillip-kruger commented 4 years ago

Relate to #282. We have code as a key supported with #295 but still need a generic key value.

Some more features:

t1 commented 3 years ago

I think we should add an instance extension, too; probably an UUID. This would be logged on the server, so when the client reports an error, it's easy to find the exact request without relying on the timestamp or so. In rfc-7807, it's an URI, so it could be an URN like urn:uuid:1234-1232534-... or an URL directly into the logging system.

piotrblasiak commented 3 years ago

I think graphql-java has the most flexible, if not the most developer friendly approach. There you register a DataFetcherExceptionHandler and override getExtensions in the thrown GraphQLError. This makes it possible to add 3 important use cases for exception extensions:

1) (Static) per class - like the @ErrorCode already does 2) Instance - additional details that do not fit into the message field of an error but that are still relevant and specific to an exception instance. 3) Handled throw - like @t1 suggests an UUID or other kind of reference, whatever the developer wants to call it. This probably needs to be added to the exception after it has been thrown.