package com.enterprise.manage.core.exception;

import com.enterprise.manage.common.web.response.Result;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;



/**
 * Global Exception Handler (全局异常处理类)
 *
 * @author PeiZhi Guo
 * 2021-2-28 15:58
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(AccessDeniedException.class)
    public Result accessDeniedException(AccessDeniedException e) {
        log.error(e.getMessage(), e);
        return Result.failure("您无权限操作");
    }

    /**
     * 系统异常
     */
    @ExceptionHandler(Exception.class)
    public Result handleException(Exception e) {
        log.error(e.getMessage(), e);
        //return Result.failure("服务器错误，请联系管理员");
        return Result.failure("服务器错误：" + e);
    }


}
