feignclient抽取异常信息

使用feign.codec.ErrorDecoder

@Configuration
public class MyErrorDecoder implements feign.codec.ErrorDecoder {

        @Override
        public Exception decode(String methodKey, Response response) {
            if (response.status() == 404) {
                return new NotFoundException(
                        response.status(),
                        response.reason()
                );
            }
            return errorStatus(methodKey, response);
        }
    }

抽取cause错误信息

HystrixRuntimeException.getCause()
instance of FeignException,如果没有自定义errorDecoder的话;
如果自定义了异常,则类似instance of NotFoundException

你可能感兴趣的:(springcloud,springboot)