|
@@ -0,0 +1,59 @@
|
|
|
+package com.persagy.fm.common.config;
|
|
|
+
|
|
|
+import com.persagy.common.enums.ResponseCode;
|
|
|
+import com.persagy.fm.common.exception.RpcException;
|
|
|
+import com.persagy.fm.common.response.FmResponseContent;
|
|
|
+import com.persagy.fm.common.response.FmResponseItem;
|
|
|
+import com.persagy.fm.common.response.FmResponseMsg;
|
|
|
+import org.aspectj.lang.annotation.AfterReturning;
|
|
|
+import org.aspectj.lang.annotation.Aspect;
|
|
|
+import org.aspectj.lang.annotation.Before;
|
|
|
+import org.aspectj.lang.annotation.Pointcut;
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
+
|
|
|
+/**
|
|
|
+ * feign调用接口,如果接口返回了报错信息,将报错信息抛出
|
|
|
+ *
|
|
|
+ * @author lixing
|
|
|
+ * @version V1.0 2021/3/24 4:55 下午
|
|
|
+ **/
|
|
|
+@Aspect
|
|
|
+@Component
|
|
|
+public class FeignExceptionHandler {
|
|
|
+
|
|
|
+ @Pointcut("@within(org.springframework.cloud.openfeign.FeignClient)")
|
|
|
+ private void pointCutMethod() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @AfterReturning(pointcut = "pointCutMethod()", returning = "res")
|
|
|
+ public void process(Object res) {
|
|
|
+ String respCode = null;
|
|
|
+ String resultMsg = null;
|
|
|
+ if (res instanceof FmResponseMsg) {
|
|
|
+ FmResponseMsg response = (FmResponseMsg) res;
|
|
|
+ respCode = response.getRespCode();
|
|
|
+ resultMsg = response.getRespMsg();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res instanceof FmResponseContent) {
|
|
|
+ FmResponseContent response = (FmResponseContent) res;
|
|
|
+ respCode = response.getRespCode();
|
|
|
+ resultMsg = response.getRespMsg();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res instanceof FmResponseItem) {
|
|
|
+ FmResponseItem response = (FmResponseItem) res;
|
|
|
+ respCode = response.getRespCode();
|
|
|
+ resultMsg = response.getRespMsg();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!ResponseCode.A00000.getCode().equals(respCode)) {
|
|
|
+ throw new RpcException(resultMsg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Before("pointCutMethod()")
|
|
|
+ public void test() {
|
|
|
+ System.out.println("test test test");
|
|
|
+ }
|
|
|
+}
|