|
@@ -4,9 +4,7 @@ import cn.reghao.dfs.store.auth.AuthException;
|
|
|
import cn.reghao.jutil.jdk.exception.ExceptionUtil;
|
|
import cn.reghao.jutil.jdk.exception.ExceptionUtil;
|
|
|
import cn.reghao.jutil.jdk.result.WebResult;
|
|
import cn.reghao.jutil.jdk.result.WebResult;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.http.HttpHeaders;
|
|
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
-import org.springframework.http.MediaType;
|
|
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
@@ -34,13 +32,17 @@ public class ControllerExceptionHandler {
|
|
|
@ResponseBody
|
|
@ResponseBody
|
|
|
public ResponseEntity<String> error(Exception e, HttpServletRequest request) {
|
|
public ResponseEntity<String> error(Exception e, HttpServletRequest request) {
|
|
|
String uri = request.getRequestURI();
|
|
String uri = request.getRequestURI();
|
|
|
- String msg = ExceptionUtil.errorMsg(e);
|
|
|
|
|
|
|
+ String msg;
|
|
|
|
|
+ if (e instanceof NullPointerException) {
|
|
|
|
|
+ msg = ExceptionUtil.stackTrace(e);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ msg = ExceptionUtil.errorMsg(e);
|
|
|
|
|
+ }
|
|
|
log.error("{} 接口抛出异常: {}", uri, msg);
|
|
log.error("{} 接口抛出异常: {}", uri, msg);
|
|
|
|
|
|
|
|
String body = WebResult.errorWithMsg(msg);
|
|
String body = WebResult.errorWithMsg(msg);
|
|
|
- HttpHeaders headers = new HttpHeaders();
|
|
|
|
|
- headers.setContentType(MediaType.APPLICATION_JSON);
|
|
|
|
|
- int status = HttpStatus.OK.value();
|
|
|
|
|
|
|
+ int status = HttpStatus.INTERNAL_SERVER_ERROR.value();
|
|
|
|
|
+ int status1 = HttpStatus.INSUFFICIENT_STORAGE.value();
|
|
|
if (e instanceof MethodArgumentNotValidException) {
|
|
if (e instanceof MethodArgumentNotValidException) {
|
|
|
// 参数校验失败
|
|
// 参数校验失败
|
|
|
MethodArgumentNotValidException exception = (MethodArgumentNotValidException) e;
|
|
MethodArgumentNotValidException exception = (MethodArgumentNotValidException) e;
|
|
@@ -50,19 +52,15 @@ public class ControllerExceptionHandler {
|
|
|
return message + "\n";
|
|
return message + "\n";
|
|
|
}).collect(Collectors.joining());
|
|
}).collect(Collectors.joining());
|
|
|
body = WebResult.errorWithMsg(errMsg);
|
|
body = WebResult.errorWithMsg(errMsg);
|
|
|
- /*body = exception.getBindingResult().getAllErrors().stream()
|
|
|
|
|
- .map(DefaultMessageSourceResolvable::getDefaultMessage)
|
|
|
|
|
- .collect(Collectors.joining());*/
|
|
|
|
|
} else if (e instanceof IllegalStateException) {
|
|
} else if (e instanceof IllegalStateException) {
|
|
|
IllegalStateException exception = (IllegalStateException) e;
|
|
IllegalStateException exception = (IllegalStateException) e;
|
|
|
Throwable throwable = exception.getCause();
|
|
Throwable throwable = exception.getCause();
|
|
|
if (throwable instanceof AuthException) {
|
|
if (throwable instanceof AuthException) {
|
|
|
status = HttpStatus.UNAUTHORIZED.value();
|
|
status = HttpStatus.UNAUTHORIZED.value();
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
body = WebResult.errorWithMsg(throwable.getMessage());
|
|
body = WebResult.errorWithMsg(throwable.getMessage());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- return ResponseEntity.status(status).headers(headers).body(body);
|
|
|
|
|
|
|
+ return ResponseEntity.status(status).body(body);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|