|
@@ -0,0 +1,26 @@
|
|
|
+package com.fjhx.xmhjc.handle;
|
|
|
+
|
|
|
+import com.fjhx.xmhjc.exception.LoginException;
|
|
|
+import com.ruoyi.common.core.domain.AjaxResult;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
+import org.springframework.http.HttpStatus;
|
|
|
+import org.springframework.web.bind.annotation.ExceptionHandler;
|
|
|
+import org.springframework.web.bind.annotation.ResponseStatus;
|
|
|
+import org.springframework.web.bind.annotation.RestControllerAdvice;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+@RestControllerAdvice
|
|
|
+public class LoginExceptionHandle {
|
|
|
+ private static final Logger log = LoggerFactory.getLogger(LoginExceptionHandle.class);
|
|
|
+
|
|
|
+
|
|
|
+ @ExceptionHandler(LoginException.class)
|
|
|
+ @ResponseStatus(value = HttpStatus.UNAUTHORIZED)
|
|
|
+ public AjaxResult handleLoginException(LoginException e, HttpServletRequest request) {
|
|
|
+ String requestURI = request.getRequestURI();
|
|
|
+ log.error("请求地址'{}',发生登录异常.", requestURI, e);
|
|
|
+ return AjaxResult.error(HttpStatus.UNAUTHORIZED.value(), e.getMessage());
|
|
|
+ }
|
|
|
+}
|