Class HttpException

All Implemented Interfaces:
Serializable
Direct Known Subclasses:
APIException, ClientErrorException, ServerErrorException

public class HttpException extends TransportException
Base exception for HTTP status code errors (4xx, 5xx).

This exception provides access to the full HTTP context:

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 Details

    • HttpException

      public HttpException(int statusCode, String message, Request request, Response response)
      Creates an HttpException with full context.
      Parameters:
      statusCode - the HTTP status code
      message - descriptive error message
      request - the original HTTP request
      response - 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 code
      message - descriptive error message
      request - the original HTTP request
      response - the HTTP response
      cause - 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

      public Response getResponse()
      Get the full HTTP response.
      Returns:
      the response object
    • getResponseBody

      public String 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:

      Overrides:
      isRetryable in class TransportException
      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

      public String toString()
      Overrides:
      toString in class TransportException