package com.persagy.bdtp.adm.aop;

import com.persagy.bdtp.adm.service.CallException;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class ExceptionAspect {

    @Pointcut("execution(public * com.persagy.bdtp.adm.controller.AppController.*(..))")
    public void handle(){

    }

    @Around("handle()")
    public Object aroundInvoke(ProceedingJoinPoint point) throws Throwable {
        try{
            return point.proceed();
        } catch (CallException e) {
            return e.getErrorResult();
        }
    }

}