Java中使用graphql进行前后端交互时,将异常信息传给前端的方法
@Component
public class GlobalExceptionHandler {
@ExceptionHandler(Exception.class)
public GraphQLError handleNormalException(Exception e, ErrorContext ctx) {
return GraphqlErrorBuilder.newError()
.path(ctx.getPath())
.errorType(ctx.getErrorType())
.message(e.getMessage())
.build();
}
}