001/* 002 * Copyright 2002-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.web.client; 018 019import java.io.IOException; 020 021import org.springframework.http.client.ClientHttpResponse; 022 023/** 024 * Strategy interface used by the {@link RestTemplate} to determine 025 * whether a particular response has an error or not. 026 * 027 * @author Arjen Poutsma 028 * @since 3.0 029 */ 030public interface ResponseErrorHandler { 031 032 /** 033 * Indicate whether the given response has any errors. 034 * <p>Implementations will typically inspect the 035 * {@link ClientHttpResponse#getStatusCode() HttpStatus} of the response. 036 * @param response the response to inspect 037 * @return {@code true} if the response indicates an error; {@code false} otherwise 038 * @throws IOException in case of I/O errors 039 */ 040 boolean hasError(ClientHttpResponse response) throws IOException; 041 042 /** 043 * Handle the error in the given response. 044 * <p>This method is only called when {@link #hasError(ClientHttpResponse)} 045 * has returned {@code true}. 046 * @param response the response with the error 047 * @throws IOException in case of I/O errors 048 */ 049 void handleError(ClientHttpResponse response) throws IOException; 050 051}