|
|
|
@ -4,6 +4,8 @@ import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException; |
|
|
|
import com.biutag.config.GlobalConfig; |
|
|
|
import com.biutag.config.GlobalConfig; |
|
|
|
import com.biutag.core.AjaxResult; |
|
|
|
import com.biutag.core.AjaxResult; |
|
|
|
import com.biutag.enums.ErrorEnum; |
|
|
|
import com.biutag.enums.ErrorEnum; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletRequest; |
|
|
|
|
|
|
|
import jakarta.servlet.http.HttpServletResponse; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.HttpStatus; |
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException; |
|
|
|
import org.springframework.http.converter.HttpMessageNotReadableException; |
|
|
|
@ -33,11 +35,11 @@ public class GlobalException { |
|
|
|
@ResponseStatus(HttpStatus.OK) |
|
|
|
@ResponseStatus(HttpStatus.OK) |
|
|
|
@ExceptionHandler(Exception.class) |
|
|
|
@ExceptionHandler(Exception.class) |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult<Object> handleException(Exception e) { |
|
|
|
public AjaxResult<Object> handleException(Exception e, HttpServletResponse response) { |
|
|
|
if (GlobalConfig.debug) { |
|
|
|
if ("application/javascript;charset=UTF-8".equals(response.getHeader("Content-Type"))) { |
|
|
|
e.printStackTrace(); |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
log.error("系统异常 {}", e.getMessage()); |
|
|
|
log.error("系统异常 {}", e.getMessage(), e); |
|
|
|
return AjaxResult.failed(ErrorEnum.SYSTEM_ERROR.getCode(), e.getMessage()); |
|
|
|
return AjaxResult.failed(ErrorEnum.SYSTEM_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -48,6 +50,7 @@ public class GlobalException { |
|
|
|
@ExceptionHandler(NoHandlerFoundException.class) |
|
|
|
@ExceptionHandler(NoHandlerFoundException.class) |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult<Object> handleNoHandlerFoundException(NoHandlerFoundException e) { |
|
|
|
public AjaxResult<Object> handleNoHandlerFoundException(NoHandlerFoundException e) { |
|
|
|
|
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(ErrorEnum.REQUEST_404_ERROR.getCode(), e.getMessage()); |
|
|
|
return AjaxResult.failed(ErrorEnum.REQUEST_404_ERROR.getCode(), e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -60,6 +63,7 @@ public class GlobalException { |
|
|
|
public AjaxResult<Object> handleException(BaseException e) { |
|
|
|
public AjaxResult<Object> handleException(BaseException e) { |
|
|
|
int code = e.getCode(); |
|
|
|
int code = e.getCode(); |
|
|
|
String msg = e.getMsg(); |
|
|
|
String msg = e.getMsg(); |
|
|
|
|
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -73,6 +77,7 @@ public class GlobalException { |
|
|
|
BindingResult bindingResult = e.getBindingResult(); |
|
|
|
BindingResult bindingResult = e.getBindingResult(); |
|
|
|
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode(); |
|
|
|
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage(); |
|
|
|
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage(); |
|
|
|
|
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -84,8 +89,8 @@ public class GlobalException { |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult<Object> handlePathException(MissingServletRequestParameterException e) { |
|
|
|
public AjaxResult<Object> handlePathException(MissingServletRequestParameterException e) { |
|
|
|
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode(); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
return AjaxResult.failed(code, e.getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -98,6 +103,7 @@ public class GlobalException { |
|
|
|
BindingResult bindingResult = e.getBindingResult(); |
|
|
|
BindingResult bindingResult = e.getBindingResult(); |
|
|
|
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.PARAMS_VALID_ERROR.getCode(); |
|
|
|
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage(); |
|
|
|
String msg = Objects.requireNonNull(bindingResult.getFieldError()).getDefaultMessage(); |
|
|
|
|
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -110,6 +116,7 @@ public class GlobalException { |
|
|
|
public AjaxResult<Object> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { |
|
|
|
public AjaxResult<Object> handleHttpMessageNotReadableException(HttpMessageNotReadableException e) { |
|
|
|
Integer code = ErrorEnum.PARAMS_TYPE_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.PARAMS_TYPE_ERROR.getCode(); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
|
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(code, msg.split(";")[0]); |
|
|
|
return AjaxResult.failed(code, msg.split(";")[0]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -122,6 +129,7 @@ public class GlobalException { |
|
|
|
public AjaxResult<Object> handleRequestMethodException(HttpRequestMethodNotSupportedException e) { |
|
|
|
public AjaxResult<Object> handleRequestMethodException(HttpRequestMethodNotSupportedException e) { |
|
|
|
Integer code = ErrorEnum.REQUEST_METHOD_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.REQUEST_METHOD_ERROR.getCode(); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
|
|
|
|
log.error(e.getMessage()); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -147,6 +155,7 @@ public class GlobalException { |
|
|
|
public AjaxResult<Object> handleMybatisPlusException(MybatisPlusException e) { |
|
|
|
public AjaxResult<Object> handleMybatisPlusException(MybatisPlusException e) { |
|
|
|
Integer code = ErrorEnum.ASSERT_MYBATIS_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.ASSERT_MYBATIS_ERROR.getCode(); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
String msg = Objects.requireNonNull(e.getMessage()); |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
return AjaxResult.failed(code, msg); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -155,6 +164,7 @@ public class GlobalException { |
|
|
|
@ResponseBody |
|
|
|
@ResponseBody |
|
|
|
public AjaxResult<Object> handleMinioOperateException(MinioOperateException e) { |
|
|
|
public AjaxResult<Object> handleMinioOperateException(MinioOperateException e) { |
|
|
|
Integer code = ErrorEnum.SYSTEM_ERROR.getCode(); |
|
|
|
Integer code = ErrorEnum.SYSTEM_ERROR.getCode(); |
|
|
|
|
|
|
|
log.error(e.getMessage(), e); |
|
|
|
return AjaxResult.failed(code, String.format("Minio 操作异常:%s", e.getMessage())); |
|
|
|
return AjaxResult.failed(code, String.format("Minio 操作异常:%s", e.getMessage())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|