Package com.chargebee.v4.exceptions
Class HttpException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
com.chargebee.v4.exceptions.ChargebeeException
com.chargebee.v4.exceptions.TransportException
com.chargebee.v4.exceptions.HttpException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
APIException,ClientErrorException,ServerErrorException
Base exception for HTTP status code errors (4xx, 5xx).
This exception provides access to the full HTTP context:
getStatusCode()- The HTTP status codeTransportException.getRequest()- The original HTTP requestgetResponse()- The HTTP responsegetResponseBody()- The response body as stringTransportException.getUrl()- Convenience method for request URLTransportException.getHttpMethod()- Convenience method for HTTP method
Exception hierarchy:
HttpException ├── ClientErrorException (4xx errors) ├── ServerErrorException (5xx errors) └── APIException (Chargebee API errors with structured response)
Example usage:
try {
client.customers().retrieve("invalid_id");
} catch (HttpException e) {
System.err.println("HTTP " + e.getStatusCode() + ": " + e.getMessage());
System.err.println("URL: " + e.getUrl());
System.err.println("Response: " + e.getResponseBody());
if (e.isRetryable()) {
// Retry logic
}
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionHttpException(int statusCode, String message, Request request, Response response) Creates an HttpException with full context.HttpException(int statusCode, String message, Request request, Response response, Throwable cause) Creates an HttpException with full context and cause. -
Method Summary
Modifier and TypeMethodDescriptionGet the full HTTP response.Get the response body as string for error details.intGet the HTTP status code.booleanCheck if this is a client error (4xx status code).booleanCheck if this HTTP error is retryable.booleanCheck if this is a server error (5xx status code).toString()Methods inherited from class com.chargebee.v4.exceptions.TransportException
getHttpMethod, getRequest, getUrlMethods inherited from class java.lang.Throwable
addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
-
Constructor Details
-
HttpException
Creates an HttpException with full context.- Parameters:
statusCode- the HTTP status codemessage- descriptive error messagerequest- the original HTTP requestresponse- the HTTP response
-
HttpException
public HttpException(int statusCode, String message, Request request, Response response, Throwable cause) Creates an HttpException with full context and cause.- Parameters:
statusCode- the HTTP status codemessage- descriptive error messagerequest- the original HTTP requestresponse- the HTTP responsecause- the underlying cause
-
-
Method Details
-
getStatusCode
public int getStatusCode()Get the HTTP status code.- Returns:
- the HTTP status code (e.g., 400, 404, 500)
-
getResponse
Get the full HTTP response.- Returns:
- the response object
-
getResponseBody
Get the response body as string for error details.- Returns:
- the response body, or null if response is not available
-
isRetryable
public boolean isRetryable()Check if this HTTP error is retryable.By default, HTTP errors are not retryable. Subclasses override this:
ServerErrorException- true for most 5xx (except 501)ClientErrorException- true only for 429 (rate limiting)
- Overrides:
isRetryablein classTransportException- Returns:
- false by default
-
isClientError
public boolean isClientError()Check if this is a client error (4xx status code).- Returns:
- true if status code is 4xx
-
isServerError
public boolean isServerError()Check if this is a server error (5xx status code).- Returns:
- true if status code is 5xx
-
toString
- Overrides:
toStringin classTransportException
-