use of com.recurly.v3.exception.InternalServerException in project recurly-client-java by recurly.
the class ExceptionFactory method getExceptionClass.
@SuppressWarnings("unchecked")
public static <T extends RecurlyException> T getExceptionClass(Response response) {
String requestId = response.header("X-Request-Id", "none");
int code = response.code();
String message = "Unexpected " + code + " Error. Recurly Request Id: " + requestId;
switch(code) {
case 500:
return (T) new InternalServerException(message, null);
case 502:
return (T) new BadGatewayException(message, null);
case 503:
return (T) new ServiceUnavailableException(message, null);
case 504:
return (T) new TimeoutException(message, null);
case 304:
return (T) new NotModifiedException(message, null);
case 400:
return (T) new BadRequestException(message, null);
case 401:
return (T) new UnauthorizedException(message, null);
case 402:
return (T) new PaymentRequiredException(message, null);
case 403:
return (T) new ForbiddenException(message, null);
case 404:
return (T) new NotFoundException(message, null);
case 406:
return (T) new NotAcceptableException(message, null);
case 412:
return (T) new PreconditionFailedException(message, null);
case 422:
return (T) new UnprocessableEntityException(message, null);
case 429:
return (T) new TooManyRequestsException(message, null);
default:
return (T) new ApiException(message, null);
}
}
Aggregations