graphql-java: More customizable errors would be nice
It’s currently impossible to report errors whose message does not start with "Exception while fetching data: "
.
Overriding ExecutionStrategy.resolveField is a bad workaround (and see #208).
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 7
- Comments: 23 (12 by maintainers)
FWIW, here’s a Jackson serializer (if anyone is using Jackson) for
ExecutionResult
that will skip printing the stacks if an error is anExceptionWhileDataFetching
:Implementation:
Test:
@dminkovsky thanks! I was looking for something similar. I won’t want risk exposing internals by showing a stacktrace. Your code worked fine except for one thing: Had to change if (!locations.isEmpty()) { into if (locations != null && !locations.isEmpty()) {
Or I’d get NPEs while serializing (in my case a dataFetcher threw an IllegalArgumentException), and “location” was null
I guess my point is that it’d be nice to add errors to the env that don’t necessarily even have an exception, that have an errorType other than DataFetchingException, and it does look indeed like the message has a prefix I can’t control.
Thanks for that stack trace
See http://graphql-java.readthedocs.io/en/v4/execution.html#exceptions-while-fetching-data on how you can customize your output
💯 : I am facing the same issue. It would be really convenient to be able to define an error formatting strategy (e.g. I would like to exclude the stacktrace in my case).
For:
query throws { error(message:"hello") }
with:I get: