Spring Boot GraphQL Tutorial #8 - Exception Handling with ExceptionHandler

preview_player
Показать описание
Spring boot graphql supports Spring web's @ExceptionHandler annotations.

With this approach I recommend you create an "catch all" exception handler. This will ensure any spring, feign, jooq, hibernate etc runtime exception messages are not propagated to the client, but instead are shown a internal server error message. To sum up, if its not defined handled exception type, then show internal server error. Lets not leak info.

By default, graphql will create a DefaultGraphQLErrorHandler bean. This bean will be invoked with a list of all the graphql exceptions/errors that occurred during the query. The bean will then try to find a matching ExceptionHandler for the error's exception. If it finds a matching handler, it will then swap its wrapped error (containing the real exception) with your ErrorHandlers response object.

See you in the next video. Spring Boot GraphQL Exception Handling with a custom GraphQLErrorHandler implementation.

Cheers!
Philip

Рекомендации по теме
Комментарии
Автор

Hi Philip, first of all thanks for sharing this tutorial. Its really awesome and very helpful. I followed the video for ExceptionHandling and can see the message "Client unavailable" on console but still getting "Internal Server Error(s) while executing query" in response. It looks like mapping with GraphQLException is not happing because controller is not coming to return new ThrowableGraphQLError(e); please help

manjeshk
Автор

Hi Philip,
I am getting "Cannot resolve symbol throwablegraphqlerror", can you please suggest what should i do?

parth
Автор

seems this approach does not work for exception thrown from security filters

sergmayakov
Автор

Hi Philip, can you please let me know how to handle "meesage:" "validation error of type FieldUndefined:Field 'name' in type BankAccount is undefined @bankAccount/name"
This error comes when we pass incorrect schema while sending query

gauravbhandari
Автор

Hi! This video was really useful. So... I'm, getting some troubles with the implementation of this. The thing is I'm using a services to process the whole request and database operations, and everything works find but the response, which is returning incomplete, such as this:
{
"errors": [
{
"message": "My error description"
}
],
"data": {
"removeProductCategory": null

As you can see I'm getting a response without the closing brackets. Do you know any possible reason for this behavior?

haroldespitia
Автор

Hi Philip, could you please let me know if this works with Spring boot 2.3.0.RELEASE and spring cloud Hoxton.SR5?

bharathkin
join shbcf.ru