org.springframework.http.client.ResponseErrorHandlerCustom Maven / Gradle / Ivy
package org.springframework.http.client;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.HttpStatus.Series;
import org.springframework.util.Assert;
import org.springframework.web.client.DefaultResponseErrorHandler;
public class ResponseErrorHandlerCustom extends DefaultResponseErrorHandler {
private List series = new ArrayList();
private List status = new ArrayList();
@Override
protected boolean hasError(HttpStatus statusCode) {
for (Series series : this.series) {
if (statusCode.series() == series) {
return true;
}
}
return false;
}
@Override
public void handleError(ClientHttpResponse response) throws IOException {
for (HttpStatus status : this.status) {
if (status.value() == response.getRawStatusCode()) {
return;
}
}
super.handleError(response);
}
public ResponseErrorHandlerCustom series(Series... series) {
Assert.notNull(series, "'series' must not be null");
this.series = Arrays.asList(series);
return this;
}
public ResponseErrorHandlerCustom status(HttpStatus... status) {
Assert.notNull(status, "'status' must not be null");
this.status = Arrays.asList(status);
return this;
}
public void setSeries(Series... series) {
Assert.notNull(series, "'series' must not be null");
this.series = Arrays.asList(series);
}
public void setStatus(HttpStatus... status) {
Assert.notNull(status, "'status' must not be null");
this.status = Arrays.asList(status);
}
}