|
@@ -11,6 +11,7 @@ import org.springframework.validation.BindException;
|
|
|
import org.springframework.validation.FieldError;
|
|
import org.springframework.validation.FieldError;
|
|
|
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
|
import org.springframework.web.HttpMediaTypeNotSupportedException;
|
|
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
import org.springframework.web.HttpRequestMethodNotSupportedException;
|
|
|
|
|
+import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
|
|
|
|
@@ -78,6 +79,24 @@ public class BaseExceptionHandler {
|
|
|
return new FebsResponse().message(message.toString());
|
|
return new FebsResponse().message(message.toString());
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 统一处理请求参数校验(json)
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param e ConstraintViolationException
|
|
|
|
|
+ * @return FebsResponse
|
|
|
|
|
+ */
|
|
|
|
|
+ @ExceptionHandler(MethodArgumentNotValidException.class)
|
|
|
|
|
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
|
|
+ public FebsResponse handlerMethodArgumentNotValidException(MethodArgumentNotValidException e) {
|
|
|
|
|
+ StringBuilder message = new StringBuilder();
|
|
|
|
|
+ for (FieldError error : e.getBindingResult().getFieldErrors()) {
|
|
|
|
|
+ message.append(error.getField()).append(error.getDefaultMessage()).append(",");
|
|
|
|
|
+ }
|
|
|
|
|
+ message = new StringBuilder(message.substring(0, message.length() - 1));
|
|
|
|
|
+ log.error(message.toString(), e);
|
|
|
|
|
+ return new FebsResponse().message(message.toString());
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
@ExceptionHandler(value = FileDownloadException.class)
|
|
@ExceptionHandler(value = FileDownloadException.class)
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
public void handleFileDownloadException(FileDownloadException e) {
|
|
public void handleFileDownloadException(FileDownloadException e) {
|