- 自定义ErrorDecoder
@Slf4j public class FeignErrorDecoder implements ErrorDecoder { @Override public Exception decode(String methodKey, Response response) { String message = response.reason(); try { if (response.body() != null) { message = IOUtils.toString(response.body().asInputStream(), StandardCharsets.UTF_8); } } catch (Exception e) { log.error("methodKey: {}, decode message error: , methodKey, e); } return new RuntimeException("[" + methodKey + "], status: " + response.status() + ", message: " + message); } }
- 编写Feign 配置类
public class FeignConfiguration { @Bean feign.Logger.Level feignLoggerLevel() { return feign.Logger.Level.BASIC; } @Bean @Primary public FeignErrorDecoder errorDecoder() { return new FeignErrorDecoder(); } }
11-20
12-06
2万+
11-17