|
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.exc.InputCoercionException;
|
|
import com.fdkankan.sale.common.ResultCode;
|
|
import com.fdkankan.sale.common.ResultCode;
|
|
import com.fdkankan.sale.common.ResultData;
|
|
import com.fdkankan.sale.common.ResultData;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
import org.springframework.dao.DataIntegrityViolationException;
|
|
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;
|
|
@@ -23,7 +24,10 @@ public class GlobalExceptionHandler {
|
|
@ExceptionHandler(value = Exception.class)
|
|
@ExceptionHandler(value = Exception.class)
|
|
public ResultData exceptionHandler(Exception e) throws Exception {
|
|
public ResultData exceptionHandler(Exception e) throws Exception {
|
|
log.error("服务错误:", e);
|
|
log.error("服务错误:", e);
|
|
- if(e .getCause().getMessage() != null && e.getCause().getMessage().contains("out of range of")){
|
|
|
|
|
|
+ if(e == null || e.getCause() == null || StringUtils.isBlank(e.getCause().getMessage())){
|
|
|
|
+ return ResultData.error( 500, "系统错误");
|
|
|
|
+ }
|
|
|
|
+ if(e.getCause().getMessage() != null && e.getCause().getMessage().contains("out of range of")){
|
|
return ResultData.error(ResultCode.DATA_TOO_LONG);
|
|
return ResultData.error(ResultCode.DATA_TOO_LONG);
|
|
}
|
|
}
|
|
return ResultData.error( 500, e.getCause().getMessage());
|
|
return ResultData.error( 500, e.getCause().getMessage());
|