package org.springframework.web.client;
import java.nio.charset.Charset;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.lang.Nullable;
public class HttpClientErrorException extends HttpStatusCodeException {
private static final long serialVersionUID = 5177019431887513952L;
public HttpClientErrorException(HttpStatus statusCode) {
super(statusCode);
}
public HttpClientErrorException(HttpStatus statusCode, String statusText) {
super(statusCode, statusText);
}
public HttpClientErrorException(
HttpStatus statusCode, String statusText, @Nullable byte[] body, @Nullable Charset responseCharset) {
super(statusCode, statusText, body, responseCharset);
}
public (HttpStatus statusCode, String statusText,
@Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset responseCharset) {
super(statusCode, statusText, headers, body, responseCharset);
}
public (String message, HttpStatus statusCode, String statusText,
@Nullable HttpHeaders headers, @Nullable byte[] body, @Nullable Charset responseCharset) {
super(message, statusCode, statusText, headers, body, responseCharset);
}
public static HttpClientErrorException (
HttpStatus statusCode, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
return create(null, statusCode, statusText, headers, body, charset);
}
public static HttpClientErrorException (@Nullable String message, HttpStatus statusCode,
String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
switch (statusCode) {
case BAD_REQUEST:
return message != null ?
new HttpClientErrorException.BadRequest(message, statusText, headers, body, charset) :
new HttpClientErrorException.BadRequest(statusText, headers, body, charset);
case UNAUTHORIZED:
return message != null ?
new HttpClientErrorException.Unauthorized(message, statusText, headers, body, charset) :
new HttpClientErrorException.Unauthorized(statusText, headers, body, charset);
case FORBIDDEN:
return message != null ?
new HttpClientErrorException.Forbidden(message, statusText, headers, body, charset) :
new HttpClientErrorException.Forbidden(statusText, headers, body, charset);
case NOT_FOUND:
return message != null ?
new HttpClientErrorException.NotFound(message, statusText, headers, body, charset) :
new HttpClientErrorException.NotFound(statusText, headers, body, charset);
case METHOD_NOT_ALLOWED:
return message != null ?
new HttpClientErrorException.MethodNotAllowed(message, statusText, headers, body, charset) :
new HttpClientErrorException.MethodNotAllowed(statusText, headers, body, charset);
case NOT_ACCEPTABLE:
return message != null ?
new HttpClientErrorException.NotAcceptable(message, statusText, headers, body, charset) :
new HttpClientErrorException.NotAcceptable(statusText, headers, body, charset);
case CONFLICT:
return message != null ?
new HttpClientErrorException.Conflict(message, statusText, headers, body, charset) :
new HttpClientErrorException.Conflict(statusText, headers, body, charset);
case GONE:
return message != null ?
new HttpClientErrorException.Gone(message, statusText, headers, body, charset) :
new HttpClientErrorException.Gone(statusText, headers, body, charset);
case UNSUPPORTED_MEDIA_TYPE:
return message != null ?
new HttpClientErrorException.UnsupportedMediaType(message, statusText, headers, body, charset) :
new HttpClientErrorException.UnsupportedMediaType(statusText, headers, body, charset);
case TOO_MANY_REQUESTS:
return message != null ?
new HttpClientErrorException.TooManyRequests(message, statusText, headers, body, charset) :
new HttpClientErrorException.TooManyRequests(statusText, headers, body, charset);
case UNPROCESSABLE_ENTITY:
return message != null ?
new HttpClientErrorException.UnprocessableEntity(message, statusText, headers, body, charset) :
new HttpClientErrorException.UnprocessableEntity(statusText, headers, body, charset);
default:
return message != null ?
new HttpClientErrorException(message, statusCode, statusText, headers, body, charset) :
new HttpClientErrorException(statusCode, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class BadRequest extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.BAD_REQUEST, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.BAD_REQUEST, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class Unauthorized extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.UNAUTHORIZED, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.UNAUTHORIZED, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class Forbidden extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.FORBIDDEN, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.FORBIDDEN, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class NotFound extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.NOT_FOUND, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.NOT_FOUND, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class MethodNotAllowed extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.METHOD_NOT_ALLOWED, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class NotAcceptable extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.NOT_ACCEPTABLE, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class Conflict extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.CONFLICT, statusText, headers, body, charset);
}
private (String message, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.CONFLICT, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class Gone extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.GONE, statusText, headers, body, charset);
}
private (String message, String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.GONE, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class UnsupportedMediaType extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.UNSUPPORTED_MEDIA_TYPE, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class UnprocessableEntity extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.UNPROCESSABLE_ENTITY, statusText, headers, body, charset);
}
}
@SuppressWarnings("serial")
public static final class TooManyRequests extends HttpClientErrorException {
private (String statusText, HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset);
}
private (String message, String statusText,
HttpHeaders headers, byte[] body, @Nullable Charset charset) {
super(message, HttpStatus.TOO_MANY_REQUESTS, statusText, headers, body, charset);
}
}
}