restTemplate处理请求状态非200的逻辑


    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory){
        RestTemplate restTemplate = new RestTemplate(factory);
        restTemplate.setErrorHandler(new ResponseErrorHandler() {
            @Override
            public boolean hasError(ClientHttpResponse response)  {
                return true;
            }
            @Override
            public void handleError(ClientHttpResponse response) throws IOException{
                int rawStatusCode = response.getRawStatusCode();
                if(rawStatusCode!=200){
                    throw new RuntimeException("请求失败!状态:"+rawStatusCode+";信息:系统繁忙!请稍后重试!");
                }
            }
        });
        return restTemplate;
    }