|
@@ -1,36 +0,0 @@
|
|
-package com.xy.config;
|
|
|
|
-
|
|
|
|
-import com.alibaba.fastjson.JSONException;
|
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
|
-import com.xy.error.CommRuntimeException;
|
|
|
|
-import feign.Response;
|
|
|
|
-import feign.Util;
|
|
|
|
-import feign.codec.ErrorDecoder;
|
|
|
|
-import jdk.nashorn.internal.runtime.regexp.joni.exception.InternalException;
|
|
|
|
-import org.springframework.context.annotation.Configuration;
|
|
|
|
-
|
|
|
|
-import java.io.IOException;
|
|
|
|
-
|
|
|
|
-@Configuration
|
|
|
|
-public class FeignErrorDecoder implements ErrorDecoder {
|
|
|
|
-
|
|
|
|
- @Override
|
|
|
|
- public Exception decode(final String methodKey, final Response response) {
|
|
|
|
- try {
|
|
|
|
- String message = Util.toString(response.body().asReader());
|
|
|
|
- try {
|
|
|
|
- JSONObject jsonObject = JSONObject.parseObject(message);
|
|
|
|
- // 包装成自己自定义的异常
|
|
|
|
- return new CommRuntimeException(jsonObject.getString("message"));
|
|
|
|
- } catch (JSONException e) {
|
|
|
|
- e.printStackTrace();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- } catch (IOException var4) {
|
|
|
|
- return new InternalException(var4.getMessage());
|
|
|
|
- }
|
|
|
|
- return decode(methodKey, response);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-}
|
|
|