|
@@ -2,12 +2,15 @@ package com.uas.sso.sso.backend.config;
|
|
|
|
|
|
|
|
import com.uas.sso.sso.backend.support.ResultBean;
|
|
import com.uas.sso.sso.backend.support.ResultBean;
|
|
|
import java.io.IOException;
|
|
import java.io.IOException;
|
|
|
|
|
+import java.util.List;
|
|
|
import org.springframework.http.HttpHeaders;
|
|
import org.springframework.http.HttpHeaders;
|
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
|
|
|
+import org.springframework.validation.ObjectError;
|
|
|
|
|
+import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
import org.springframework.web.bind.annotation.ControllerAdvice;
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
@@ -55,4 +58,21 @@ public class ControllerExceptionHandler extends ResponseEntityExceptionHandler {
|
|
|
headers.add("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
headers.add("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
|
return handleExceptionInternal(ex, new ResultBean<>(ex), headers, status, request);
|
|
return handleExceptionInternal(ex, new ResultBean<>(ex), headers, status, request);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected ResponseEntity<Object> handleMethodArgumentNotValid(
|
|
|
|
|
+ MethodArgumentNotValidException ex, HttpHeaders headers, HttpStatus status,
|
|
|
|
|
+ WebRequest request) {
|
|
|
|
|
+ if (logger.isDebugEnabled()) {
|
|
|
|
|
+ logger.debug("Validation Error:", ex);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 设置响应结果取参数校验失败第一条原因
|
|
|
|
|
+ ResultBean<Object> resultBean = new ResultBean<>(ex);
|
|
|
|
|
+ List<ObjectError> allErrors = ex.getBindingResult().getAllErrors();
|
|
|
|
|
+ resultBean.setMessage(allErrors.get(0).getDefaultMessage());
|
|
|
|
|
+
|
|
|
|
|
+ headers.add("Content-Type", MediaType.APPLICATION_JSON_UTF8_VALUE);
|
|
|
|
|
+ return handleExceptionInternal(ex, resultBean, headers, status, request);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|