Defensively build GraphQLError

GraphqlErrorBuilder expects a non-null error message so we need to
check if the exception has one, or otherwise the resulting assert
error masks the original one.
This commit is contained in:
Rossen Stoyanchev
2021-08-30 16:49:28 +01:00
parent cae12820e4
commit 8cebe20a56

View File

@@ -33,6 +33,7 @@ import reactor.core.publisher.Mono;
import reactor.util.context.ContextView;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
import org.springframework.web.client.ExtractingResponseErrorHandler;
/**
@@ -88,11 +89,11 @@ class ExceptionResolversExceptionHandler implements DataFetcherExceptionHandler
}
private DataFetcherExceptionHandlerResult applyDefaultHandling(Throwable ex, DataFetchingEnvironment env) {
GraphQLError error = GraphqlErrorBuilder.newError(env)
.message(ex.getMessage())
.errorType(ErrorType.INTERNAL_ERROR)
.build();
return DataFetcherExceptionHandlerResult.newResult(error).build();
GraphqlErrorBuilder errorBuilder = GraphqlErrorBuilder.newError(env).errorType(ErrorType.INTERNAL_ERROR);
if (StringUtils.hasText(ex.getMessage())) {
errorBuilder.message(ex.getMessage());
}
return DataFetcherExceptionHandlerResult.newResult(errorBuilder.build()).build();
}
}