All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.bootx.platform.starter.auth.handler.SaExceptionHandler Maven / Gradle / Ivy

There is a newer version: 1.3.6.2
Show newest version
package cn.bootx.platform.starter.auth.handler;

import cn.bootx.platform.common.core.code.CommonCode;
import cn.bootx.platform.common.core.rest.Res;
import cn.bootx.platform.common.core.rest.ResResult;
import cn.dev33.satoken.exception.SaTokenException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 过滤SaTokenException,需要运行在 RestExceptionHandler 之前
 *
 * @author xxm
 * @since 2021/8/5
 */
@Order(Ordered.LOWEST_PRECEDENCE - 1)
@Slf4j
@RestControllerAdvice
public class SaExceptionHandler {

    /**
     * sa鉴权业务异常
     */
    @ExceptionHandler(SaTokenException.class)
    public ResResult handleBusinessException(SaTokenException ex) {
        log.info(ex.getMessage(), ex);
        return Res.response(CommonCode.FAIL_CODE, ex.getMessage());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy