hjl
2024-07-26 f8cc44e926fd22f9d1d864dc684c827f6960270b
ruoyi-common/ruoyi-common-security/src/main/java/com/ruoyi/common/security/handler/GlobalExceptionHandler.java
@@ -13,6 +13,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindException;
import org.springframework.validation.FieldError;
import org.springframework.web.HttpRequestMethodNotSupportedException;
import org.springframework.web.bind.MethodArgumentNotValidException;
import org.springframework.web.bind.MissingPathVariableException;
@@ -122,16 +123,6 @@
    }
    /**
     * 自定义验证异常
     */
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
        log.error(e.getMessage(), e);
        String message = e.getBindingResult().getFieldError().getDefaultMessage();
        return AjaxResult.error(message);
    }
    /**
     * 内部认证异常
     */
    @ExceptionHandler(InnerAuthException.class)
@@ -148,11 +139,24 @@
    }
    /**
     * 演示模式异常
     * 自定义异常
     */
    @ExceptionHandler(GlobalException.class)
    public R<String> handleDemoModeException(GlobalException g) {
        return R.fail(g.getDetailMessage());
        return R.fail(null, g.getCode() == null ? 500 : g.getCode(), g.getMessage());
    }
    /**
     * 捕获jsr303参数校验异常
     *
     * @author hjl
     */
    @ExceptionHandler(MethodArgumentNotValidException.class)
    public R<String> methodArgumentNotValidExceptionExceptionException(MethodArgumentNotValidException e) {
        FieldError fieldError = e.getBindingResult().getFieldError();
        assert fieldError != null;
        String defaultMessage = fieldError.getDefaultMessage();
        return R.fail(defaultMessage);
    }
}