|
@@ -1,6 +1,7 @@
|
|
|
package cn.cslg.pas.common.core;
|
|
|
|
|
|
import cn.cslg.pas.common.utils.Response;
|
|
|
+import cn.cslg.pas.exception.UnLoginException;
|
|
|
import cn.cslg.pas.exception.XiaoShiException;
|
|
|
import org.springframework.http.HttpStatus;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
@@ -13,11 +14,17 @@ import org.springframework.web.context.request.WebRequest;
|
|
|
@ControllerAdvice
|
|
|
public class GlobalExceptionHandler {
|
|
|
|
|
|
- @ExceptionHandler(value = {Exception.class})
|
|
|
+ @ExceptionHandler(value = {XiaoShiException.class})
|
|
|
@ResponseBody
|
|
|
public Response handleAllExceptions(XiaoShiException ex) {
|
|
|
// 返回一个包含错误信息的 HTTP 响应
|
|
|
return Response.error(ex.getErrorCode(), ex.getErrorMessage());
|
|
|
}
|
|
|
|
|
|
+ @ExceptionHandler(value = {UnLoginException.class})
|
|
|
+ @ResponseBody
|
|
|
+ public Response handleAllExceptions(UnLoginException ex) {
|
|
|
+ // 返回一个包含错误信息的 HTTP 响应
|
|
|
+ return Response.error("401", "未登录");
|
|
|
+ }
|
|
|
}
|