|
@@ -0,0 +1,41 @@
|
|
|
+package com.persagy.apm.common.config;
|
|
|
+
|
|
|
+import com.persagy.apm.common.exception.RpcException;
|
|
|
+import com.persagy.apm.common.response.FeignResponseContent;
|
|
|
+import com.persagy.apm.common.response.FeignResponseItem;
|
|
|
+import com.persagy.apm.common.response.FeignResponseMsg;
|
|
|
+import com.persagy.apm.common.response.PoemsFeignResponse;
|
|
|
+import com.persagy.common.enums.ResponseCode;
|
|
|
+import org.aspectj.lang.annotation.AfterReturning;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
+
|
|
|
+/**
|
|
|
+ * feign调用poems接口,如果接口返回了报错信息,将报错信息抛出
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/24 4:55 下午
|
|
|
+ **/
|
|
|
+@Aspect
|
|
|
+public class PoemsFeignExceptionHandler {
|
|
|
+
|
|
|
+ @Pointcut("@within(org.springframework.cloud.openfeign.FeignClient)")
|
|
|
+ private void pointCutMethod() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterReturning(pointcut = "pointCutMethod()", returning = "res")
|
|
|
+ public void process(Object res) {
|
|
|
+ String result = null;
|
|
|
+ String reason = null;
|
|
|
+ if (res instanceof PoemsFeignResponse) {
|
|
|
+ PoemsFeignResponse response = (PoemsFeignResponse) res;
|
|
|
+ result = response.getResult();
|
|
|
+ reason = response.getReason();
|
|
|
+ }
|
|
|
+
|
|
|
+ String success = "success";
|
|
|
+ if (!success.equals(result)) {
|
|
|
+ throw new RpcException(reason);
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|