Search in sources :

Example 1 with Response

use of com.chao.cloud.common.entity.Response in project chao-cloud by chaojunzi.

the class FeignFallbackProxy method around.

/**
 * feign异步调用拦截
 */
@Around(value = "@annotation(com.chao.cloud.common.extra.feign.annotation.FeignFallback)")
public Object around(ProceedingJoinPoint pdj) throws Exception {
    Object obj = null;
    String serverName = "undefined";
    try {
        Method method = getMethod(pdj);
        Object target = pdj.getTarget();
        String targetString = target.toString();
        serverName = targetString.split(",")[1];
        log.info("[\nFeignClient={},\nMethod={},\nParam={}]", targetString, method, pdj.getArgs());
        obj = pdj.proceed();
    } catch (Throwable e) {
        throw new BusinessException("[Server:" + serverName + "]" + e.getMessage());
    }
    if (obj instanceof Response) {
        Response<?> result = (Response<?>) obj;
        if (!ResultCodeEnum.CODE_200.code().equals(result.getRetCode())) {
            throw new BusinessException(result.getRetMsg());
        }
    }
    return obj;
}
Also used : Response(com.chao.cloud.common.entity.Response) BusinessException(com.chao.cloud.common.exception.BusinessException) Method(java.lang.reflect.Method) Around(org.aspectj.lang.annotation.Around)

Aggregations

Response (com.chao.cloud.common.entity.Response)1 BusinessException (com.chao.cloud.common.exception.BusinessException)1 Method (java.lang.reflect.Method)1 Around (org.aspectj.lang.annotation.Around)1