|
@@ -10,6 +10,7 @@ import org.springframework.core.annotation.AnnotationUtils;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.MediaType;
|
|
|
import org.springframework.http.converter.HttpMessageConverter;
|
|
|
+import org.springframework.http.converter.HttpMessageNotReadableException;
|
|
|
import org.springframework.http.server.ServerHttpRequest;
|
|
|
import org.springframework.http.server.ServerHttpResponse;
|
|
|
import org.springframework.validation.BindingResult;
|
|
@@ -62,7 +63,16 @@ public class APIResponseAdvice implements ResponseBodyAdvice<Object> {
|
|
|
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
|
|
|
public APIResponse serverError(Throwable ex) {
|
|
|
logger.error("error", ex);
|
|
|
-// log.error(ex.getMessage(),ex);
|
|
|
+ APIResponse apiResponse = new APIResponse();
|
|
|
+ apiResponse.setCode(-1);
|
|
|
+ apiResponse.setMessage("服务器运行异常");
|
|
|
+ return apiResponse;
|
|
|
+ }
|
|
|
+
|
|
|
+ @ExceptionHandler(HttpMessageNotReadableException.class)
|
|
|
+ @ResponseStatus(HttpStatus.BAD_REQUEST)
|
|
|
+ public APIResponse messageParseException(HttpMessageNotReadableException ex) {
|
|
|
+ logger.warn("error", ex);
|
|
|
APIResponse apiResponse = new APIResponse();
|
|
|
apiResponse.setCode(-1);
|
|
|
apiResponse.setMessage("服务器运行异常");
|