我想防止 spring 将 Runtimeexceptions 的完整堆栈跟踪发送到前端。我做了这样的事情:
@ControllerAdvice
public class RestErrorHandler extends ResponseEntityExceptionHandler {
@ExceptionHandler(Exception.class)
@ResponseStatus(value = HttpStatus.INTERNAL_SERVER_ERROR)
@Override
protected ResponseEntity<Object> handleExceptionInternal(Exception e, Object body,
HttpHeaders headers, HttpStatus status, WebRequest request) {
logger.error("Error happened while executing controller.", e);
return null;
}
}
我的目标是只向前端发送错误代码,而不是其他任何东西。上述方法向前端返回状态 200 OK。应该返回什么而不是 null ?