package com.ruoyi.framework.web.exception;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;

/**
 * 拦截实现类中的异常信息
 *
 * @author hzh
 * @date 2023-09-21
 */
@Aspect
@Component
public class GlobalExceptionAspect {
    // com.ruoyi.system.service.impl
    @Around("execution(* com.ruoyi.system..*(..))") // 切入点表达式
    public Object handleExceptionALL(ProceedingJoinPoint joinPoint) throws Throwable {
        try {
            return joinPoint.proceed(); // 继续执行被拦截的方法  
        } catch (Exception e) {
            // 处理异常
            System.err.println(e);
            return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
        }
    }
}