From 2f640b1038fa331954f78ed1f4317212cf5bb34d Mon Sep 17 00:00:00 2001 From: chenlu <1320612696@qq.com> Date: 星期五, 07 六月 2024 16:56:06 +0800 Subject: [PATCH] Merge branch 'master' of http://10.153.19.25:10101/r/ERP_override --- north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) diff --git a/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java b/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java new file mode 100644 index 0000000..cba151d --- /dev/null +++ b/north-glass-erp/src/main/java/com/example/erp/exception/GlobalExceptionHandle.java @@ -0,0 +1,39 @@ +package com.example.erp.exception; + +import cn.dev33.satoken.exception.NotLoginException; +import cn.dev33.satoken.exception.NotPermissionException; +import cn.dev33.satoken.util.SaResult; +import com.example.erp.common.Constants; +import com.example.erp.common.Result; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; + +import java.util.Arrays; + +@ControllerAdvice +public class GlobalExceptionHandle { + /** + * 濡傛灉鏄痵erviceExcaption锛屽垯璋冪敤璇ユ柟娉� + */ + @ExceptionHandler(ServiceException.class) + @ResponseBody + public Result handle(ServiceException se){ + return Result.error(se.getCode(),se.getMessage()); + } + + // 鎷︽埅锛氭棤鏉冮檺寮傚父 + @ExceptionHandler(NotPermissionException.class) + @ResponseBody + public Result handlerException(NotPermissionException e) { + return Result.error(Constants.Code_401,e.getPermission()); + } + + // 鎷︽埅锛氭湭鐧诲綍寮傚父 + @ExceptionHandler(NotLoginException.class) + @ResponseBody + public Result handlerException(NotLoginException e) { + // 杩斿洖缁欏墠绔� + return Result.error(Constants.Code_402,"Please login user"); + } +} -- Gitblit v1.8.0