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; 020import java.net.URI; 021 022import org.springframework.http.HttpMethod; 023import org.springframework.http.client.ClientHttpResponse; 024 025/** 026 * Strategy interface used by the {@link RestTemplate} to determine 027 * whether a particular response has an error or not. 028 * 029 * @author Arjen Poutsma 030 * @since 3.0 031 */ 032public interface ResponseErrorHandler { 033 034 /** 035 * Indicate whether the given response has any errors. 036 * <p>Implementations will typically inspect the 037 * {@link ClientHttpResponse#getStatusCode() HttpStatus} of the response. 038 * @param response the response to inspect 039 * @return {@code true} if the response indicates an error; {@code false} otherwise 040 * @throws IOException in case of I/O errors 041 */ 042 boolean hasError(ClientHttpResponse response) throws IOException; 043 044 /** 045 * Handle the error in the given response. 046 * <p>This method is only called when {@link #hasError(ClientHttpResponse)} 047 * has returned {@code true}. 048 * @param response the response with the error 049 * @throws IOException in case of I/O errors 050 */ 051 void handleError(ClientHttpResponse response) throws IOException; 052 053 /** 054 * Alternative to {@link #handleError(ClientHttpResponse)} with extra 055 * information providing access to the request URL and HTTP method. 056 * @param url the request URL 057 * @param method the HTTP method 058 * @param response the response with the error 059 * @throws IOException in case of I/O errors 060 * @since 5.0 061 */ 062 default void handleError(URI url, HttpMethod method, ClientHttpResponse response) throws IOException { 063 handleError(response); 064 } 065 066}