package com.nju.edu.pay.handler; import cn.dev33.satoken.exception.NotLoginException; import cn.dev33.satoken.exception.NotPermissionException; import cn.dev33.satoken.exception.SaTokenException; import com.seecoder.commoncore.util.Response; 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; @RestControllerAdvice public class GlobalExceptionHandler { @ExceptionHandler(SaTokenException.class) @ResponseStatus(HttpStatus.FORBIDDEN) public Response handleException(SaTokenException ste){ ste.printStackTrace(); if(ste instanceof NotPermissionException){ return Response.failed("NOT_PERMISSION",ste.getMessage()); } if(ste instanceof NotLoginException){ return Response.failed("NOT_LOGIN",ste.getMessage()); } return Response.failed(ste.getMessage()); } @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public Response handleException(Exception e){ e.printStackTrace(); return Response.failed(e.getMessage()); } }