|  | @@ -17,7 +17,6 @@ import org.springframework.web.bind.MissingPathVariableException;
 | 
											
												
													
														|  |  import org.springframework.web.bind.annotation.ExceptionHandler;
 |  |  import org.springframework.web.bind.annotation.ExceptionHandler;
 | 
											
												
													
														|  |  import org.springframework.web.bind.annotation.RestControllerAdvice;
 |  |  import org.springframework.web.bind.annotation.RestControllerAdvice;
 | 
											
												
													
														|  |  import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
 |  |  import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  |  import javax.servlet.http.HttpServletRequest;
 |  |  import javax.servlet.http.HttpServletRequest;
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  /**
 |  |  /**
 | 
											
										
											
												
													
														|  | @@ -26,14 +25,16 @@ import javax.servlet.http.HttpServletRequest;
 | 
											
												
													
														|  |   * @author ruoyi
 |  |   * @author ruoyi
 | 
											
												
													
														|  |   */
 |  |   */
 | 
											
												
													
														|  |  @RestControllerAdvice
 |  |  @RestControllerAdvice
 | 
											
												
													
														|  | -public class GlobalExceptionHandler {
 |  | 
 | 
											
												
													
														|  | 
 |  | +public class GlobalExceptionHandler
 | 
											
												
													
														|  | 
 |  | +{
 | 
											
												
													
														|  |      private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
 |  |      private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |      /**
 |  |      /**
 | 
											
												
													
														|  |       * 权限码异常
 |  |       * 权限码异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(NotPermissionException.class)
 |  |      @ExceptionHandler(NotPermissionException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleNotPermissionException(NotPermissionException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
 |  |          log.error("请求地址'{}',权限码校验失败'{}'", requestURI, e.getMessage());
 | 
											
												
													
														|  |          return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
 |  |          return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
 | 
											
										
											
												
													
														|  | @@ -43,7 +44,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 角色权限异常
 |  |       * 角色权限异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(NotRoleException.class)
 |  |      @ExceptionHandler(NotRoleException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleNotRoleException(NotRoleException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
 |  |          log.error("请求地址'{}',角色权限校验失败'{}'", requestURI, e.getMessage());
 | 
											
												
													
														|  |          return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
 |  |          return AjaxResult.error(HttpStatus.FORBIDDEN, "没有访问权限,请联系管理员授权");
 | 
											
										
											
												
													
														|  | @@ -53,8 +55,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 请求方式不支持
 |  |       * 请求方式不支持
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
 |  |      @ExceptionHandler(HttpRequestMethodNotSupportedException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e,
 |  | 
 | 
											
												
													
														|  | -                                                          HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleHttpRequestMethodNotSupported(HttpRequestMethodNotSupportedException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
 |  |          log.error("请求地址'{}',不支持'{}'请求", requestURI, e.getMethod());
 | 
											
												
													
														|  |          return AjaxResult.error(e.getMessage());
 |  |          return AjaxResult.error(e.getMessage());
 | 
											
										
											
												
													
														|  | @@ -64,7 +66,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 业务异常
 |  |       * 业务异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(ServiceException.class)
 |  |      @ExceptionHandler(ServiceException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleServiceException(ServiceException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          log.error(e.getMessage(), e);
 |  |          log.error(e.getMessage(), e);
 | 
											
												
													
														|  |          Integer code = e.getCode();
 |  |          Integer code = e.getCode();
 | 
											
												
													
														|  |          return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
 |  |          return StringUtils.isNotNull(code) ? AjaxResult.error(code, e.getMessage()) : AjaxResult.error(e.getMessage());
 | 
											
										
											
												
													
														|  | @@ -74,7 +77,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 请求路径中缺少必需的路径变量
 |  |       * 请求路径中缺少必需的路径变量
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(MissingPathVariableException.class)
 |  |      @ExceptionHandler(MissingPathVariableException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleMissingPathVariableException(MissingPathVariableException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
 |  |          log.error("请求路径中缺少必需的路径变量'{}',发生系统异常.", requestURI, e);
 | 
											
												
													
														|  |          return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
 |  |          return AjaxResult.error(String.format("请求路径中缺少必需的路径变量[%s]", e.getVariableName()));
 | 
											
										
											
												
													
														|  | @@ -84,7 +88,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 请求参数类型不匹配
 |  |       * 请求参数类型不匹配
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(MethodArgumentTypeMismatchException.class)
 |  |      @ExceptionHandler(MethodArgumentTypeMismatchException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
 |  |          log.error("请求参数类型不匹配'{}',发生系统异常.", requestURI, e);
 | 
											
												
													
														|  |          return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
 |  |          return AjaxResult.error(String.format("请求参数类型不匹配,参数[%s]要求类型为:'%s',但输入值为:'%s'", e.getName(), e.getRequiredType().getName(), e.getValue()));
 | 
											
										
											
												
													
														|  | @@ -94,7 +99,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 拦截未知的运行时异常
 |  |       * 拦截未知的运行时异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(RuntimeException.class)
 |  |      @ExceptionHandler(RuntimeException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleRuntimeException(RuntimeException e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求地址'{}',发生未知异常.", requestURI, e);
 |  |          log.error("请求地址'{}',发生未知异常.", requestURI, e);
 | 
											
												
													
														|  |          return AjaxResult.error(e.getMessage());
 |  |          return AjaxResult.error(e.getMessage());
 | 
											
										
											
												
													
														|  | @@ -104,7 +110,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 系统异常
 |  |       * 系统异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(Exception.class)
 |  |      @ExceptionHandler(Exception.class)
 | 
											
												
													
														|  | -    public AjaxResult handleException(Exception e, HttpServletRequest request) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleException(Exception e, HttpServletRequest request)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          String requestURI = request.getRequestURI();
 |  |          String requestURI = request.getRequestURI();
 | 
											
												
													
														|  |          log.error("请求地址'{}',发生系统异常.", requestURI, e);
 |  |          log.error("请求地址'{}',发生系统异常.", requestURI, e);
 | 
											
												
													
														|  |          return AjaxResult.error(e.getMessage());
 |  |          return AjaxResult.error(e.getMessage());
 | 
											
										
											
												
													
														|  | @@ -114,7 +121,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 自定义验证异常
 |  |       * 自定义验证异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(BindException.class)
 |  |      @ExceptionHandler(BindException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleBindException(BindException e) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleBindException(BindException e)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          log.error(e.getMessage(), e);
 |  |          log.error(e.getMessage(), e);
 | 
											
												
													
														|  |          String message = e.getAllErrors().get(0).getDefaultMessage();
 |  |          String message = e.getAllErrors().get(0).getDefaultMessage();
 | 
											
												
													
														|  |          return AjaxResult.error(message);
 |  |          return AjaxResult.error(message);
 | 
											
										
											
												
													
														|  | @@ -124,7 +132,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 自定义验证异常
 |  |       * 自定义验证异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(MethodArgumentNotValidException.class)
 |  |      @ExceptionHandler(MethodArgumentNotValidException.class)
 | 
											
												
													
														|  | -    public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public Object handleMethodArgumentNotValidException(MethodArgumentNotValidException e)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          log.error(e.getMessage(), e);
 |  |          log.error(e.getMessage(), e);
 | 
											
												
													
														|  |          String message = e.getBindingResult().getFieldError().getDefaultMessage();
 |  |          String message = e.getBindingResult().getFieldError().getDefaultMessage();
 | 
											
												
													
														|  |          return AjaxResult.error(message);
 |  |          return AjaxResult.error(message);
 | 
											
										
											
												
													
														|  | @@ -134,7 +143,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 内部认证异常
 |  |       * 内部认证异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(InnerAuthException.class)
 |  |      @ExceptionHandler(InnerAuthException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleInnerAuthException(InnerAuthException e) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleInnerAuthException(InnerAuthException e)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          return AjaxResult.error(e.getMessage());
 |  |          return AjaxResult.error(e.getMessage());
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  
 |  |  
 | 
											
										
											
												
													
														|  | @@ -142,7 +152,8 @@ public class GlobalExceptionHandler {
 | 
											
												
													
														|  |       * 演示模式异常
 |  |       * 演示模式异常
 | 
											
												
													
														|  |       */
 |  |       */
 | 
											
												
													
														|  |      @ExceptionHandler(DemoModeException.class)
 |  |      @ExceptionHandler(DemoModeException.class)
 | 
											
												
													
														|  | -    public AjaxResult handleDemoModeException(DemoModeException e) {
 |  | 
 | 
											
												
													
														|  | 
 |  | +    public AjaxResult handleDemoModeException(DemoModeException e)
 | 
											
												
													
														|  | 
 |  | +    {
 | 
											
												
													
														|  |          return AjaxResult.error("演示模式,不允许操作");
 |  |          return AjaxResult.error("演示模式,不允许操作");
 | 
											
												
													
														|  |      }
 |  |      }
 | 
											
												
													
														|  |  }
 |  |  }
 |