|
|
|
@ -2,6 +2,8 @@ package com.xydl.cac.exception;
|
|
|
|
|
|
|
|
|
|
import com.xydl.cac.model.Response;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
import org.springframework.core.NestedExceptionUtils;
|
|
|
|
|
import org.springframework.http.converter.HttpMessageConversionException;
|
|
|
|
|
import org.springframework.validation.FieldError;
|
|
|
|
|
import org.springframework.web.bind.MethodArgumentNotValidException;
|
|
|
|
|
import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
|
@ -21,10 +23,16 @@ public class GlobalExceptionHandler {
|
|
|
|
|
return Response.fail(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(HttpMessageConversionException.class)
|
|
|
|
|
public Response<String> handleValidationExceptions(HttpMessageConversionException ex) {
|
|
|
|
|
String message = "类型转换异常:" + ex.getRootCause().getLocalizedMessage();
|
|
|
|
|
return Response.fail(message);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ExceptionHandler(Exception.class)
|
|
|
|
|
public Response<String> handleException(Exception ex) {
|
|
|
|
|
log.error("", ex);
|
|
|
|
|
String message = ex.getMessage();
|
|
|
|
|
String message = NestedExceptionUtils.getRootCause(ex).getLocalizedMessage();
|
|
|
|
|
return Response.fail(message);
|
|
|
|
|
}
|
|
|
|
|
}
|