blob: abcd0556a8f696a3ab0ee10152b32184e93dacc9 [file] [log] [blame]
package com.example.myproject.config;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.exception.NotPermissionException;
import cn.dev33.satoken.exception.NotRoleException;
import com.example.myproject.common.base.Result;
import com.example.myproject.exception.BusinessException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
@RestControllerAdvice
public class GlobalExceptionHandler {
@ExceptionHandler(BusinessException.class)
public Result handleException(BusinessException e) {
// 这里可以根据不同的异常类型返回不同的结果
return Result.error(e.getMessage());
}
@ExceptionHandler(value = {NotLoginException.class})
public Result unLoginHandler(){
return Result.error(401, "您还未登录");
}
@ExceptionHandler(value = {NotRoleException.class, NotPermissionException.class})
public Result handlerException() {
return Result.error(403, "您没有权限");
}
}