Class APIException
- All Implemented Interfaces:
Serializable
- Direct Known Subclasses:
BatchAPIException,InvalidRequestException,OperationFailedException,PaymentException,UbbBatchIngestionInvalidRequestException
Contains parsed error information from the API response with the following attributes:
- message - Descriptive information about the error (for developer consumption)
- type - Groups errors based on error handling routine (payment, invalid_request, operation_failed)
- api_error_code - Specific code for handling specific errors
- param - The parameter name if error is due to a specific parameter
- error_cause_id - Chargebee-defined code for standardizing errors across gateway services
Use getErrorType() for strongly-typed error type handling.
Example usage:
try {
// API call
} catch (InvalidRequestException e) {
ErrorType type = e.getErrorType();
ApiErrorCode errorCode = e.getApiErrorCode();
List<String> invalidParams = e.getParams();
String causeId = e.getErrorCauseId();
// Type-safe error handling with enum
if (errorCode instanceof BadRequestApiErrorCode) {
BadRequestApiErrorCode code = (BadRequestApiErrorCode) errorCode;
if (code == BadRequestApiErrorCode.DUPLICATE_ENTRY) {
// Handle duplicate entry
}
}
} catch (PaymentException e) {
// Check error_cause_id for gateway-specific error handling
if (e.getErrorCauseId() != null) {
System.out.println("Gateway error cause: " + e.getErrorCauseId());
}
}
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionAPIException(int statusCode, String type, ApiErrorCode apiErrorCode, String message, String jsonResponse, Request request, Response response) -
Method Summary
Modifier and TypeMethodDescriptionGet the API error code as a strongly-typed enum.Get the raw API error code string as returned by the API.Get the error cause ID - a Chargebee-defined code for standardizing errors across different gateway services.Get the error type as a strongly-typed enum.Get the full JSON response as string.getParam()Get the first parameter name that caused the error.Get the parameter name(s) that caused the error.getType()Get the raw error type string as returned by the API.booleanAPI errors are generally not retryable as they indicate business logic issues.toString()Methods inherited from class com.chargebee.v4.exceptions.HttpException
getResponse, getResponseBody, getStatusCode, isClientError, isServerErrorMethods 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
-
APIException
-
-
Method Details
-
getErrorType
Get the error type as a strongly-typed enum. Use this for programmatic error handling with type safety.The type groups errors based on the error handling routine required:
ErrorType.PAYMENT- Payment-related errorsErrorType.INVALID_REQUEST- Validation and request errorsErrorType.OPERATION_FAILED- Business logic errors
- Returns:
- the error type enum, or
ErrorType._UNKNOWNfor unrecognized types
-
getType
Get the raw error type string as returned by the API. Use this when you need the exact API value or for logging.Possible values: "payment", "invalid_request", "operation_failed", or null
- Returns:
- the raw error type string, may be null
-
getApiErrorCode
Get the API error code as a strongly-typed enum.The returned enum implements
ApiErrorCodeand can be cast to the specific enum type based on the HTTP status code:ApiErrorCode code = e.getApiErrorCode(); if (code instanceof BadRequestApiErrorCode) { BadRequestApiErrorCode badRequestCode = (BadRequestApiErrorCode) code; if (badRequestCode == BadRequestApiErrorCode.DUPLICATE_ENTRY) { // Handle duplicate } }- Returns:
- the API error code as a typed enum
-
getApiErrorCodeRaw
Get the raw API error code string as returned by the API. Use this when you need the exact API value or for logging.- Returns:
- the raw API error code string
-
getParams
Get the parameter name(s) that caused the error.This is provided when the error is due to a specific parameter. The parameter name matches the API documentation (cURL format).
Note: For URL path parameters like customer_id, if invalid, a resource_not_found error is thrown without the param attribute.
- Returns:
- list of parameter names that caused the error, empty if not parameter-specific
-
getParam
Get the first parameter name that caused the error. Convenience method when only one parameter is expected.- Returns:
- the first parameter name, or null if no parameters
-
getErrorCauseId
Get the error cause ID - a Chargebee-defined code for standardizing errors across different gateway services.This helps in identifying and handling errors consistently across different payment gateways.
- Returns:
- the error cause ID, may be null if not applicable
-
getJsonResponse
Get the full JSON response as string. Useful for debugging or extracting additional error details not covered by the typed fields.- Returns:
- the full JSON error response
-
isRetryable
public boolean isRetryable()API errors are generally not retryable as they indicate business logic issues.Exceptions that may warrant retry:
- 429 Too Many Requests - Rate limiting
- 5xx Server errors - Temporary server issues
- Overrides:
isRetryablein classHttpException- Returns:
- true only for 429 or 5xx status codes
-
toString
- Overrides:
toStringin classHttpException
-