Package com.chargebee.v4.exceptions
Class ClientErrorException
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
com.chargebee.v4.exceptions.ClientErrorException
- All Implemented Interfaces:
Serializable
Exception for 4xx HTTP status codes (client errors).
Client errors indicate issues with the request itself:
- 400 Bad Request - Invalid request format or parameters
- 401 Unauthorized - Missing or invalid authentication
- 403 Forbidden - Valid auth but insufficient permissions
- 404 Not Found - Resource doesn't exist
- 409 Conflict - Resource state conflict
- 422 Unprocessable Entity - Validation errors
- 429 Too Many Requests - Rate limiting (retryable)
Convenience methods for checking specific error types:
try {
client.customers().retrieve("invalid_id");
} catch (ClientErrorException e) {
if (e.isNotFound()) {
// Customer doesn't exist
} else if (e.isUnauthorized()) {
// Check API key
} else if (e.isTooManyRequests()) {
// Back off and retry
Thread.sleep(e.getRetryAfterMs());
}
}
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intHTTP status code for rate limiting. -
Constructor Summary
ConstructorsConstructorDescriptionClientErrorException(int statusCode, String message, Request request, Response response) Creates a ClientErrorException.ClientErrorException(int statusCode, String message, Request request, Response response, Throwable cause) Creates a ClientErrorException with cause. -
Method Summary
Modifier and TypeMethodDescriptionlongGet the retry-after delay in milliseconds from response headers.booleanCheck if this is a 400 Bad Request error.booleanCheck if this is a 409 Conflict error.booleanCheck if this is a 403 Forbidden error.booleanCheck if this is a 405 Method Not Allowed error.booleanCheck if this is a 404 Not Found error.booleanClient errors are generally not retryable, except for 429 Too Many Requests.booleanCheck if this is a 429 Too Many Requests error.booleanCheck if this is a 401 Unauthorized error.booleanCheck if this is a 422 Unprocessable Entity error.Methods inherited from class com.chargebee.v4.exceptions.HttpException
getResponse, getResponseBody, getStatusCode, isClientError, isServerError, toStringMethods 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
-
Field Details
-
TOO_MANY_REQUESTS
public static final int TOO_MANY_REQUESTSHTTP status code for rate limiting.- See Also:
-
-
Constructor Details
-
ClientErrorException
Creates a ClientErrorException.- Parameters:
statusCode- the HTTP status code (4xx)message- descriptive error messagerequest- the original HTTP requestresponse- the HTTP response
-
ClientErrorException
public ClientErrorException(int statusCode, String message, Request request, Response response, Throwable cause) Creates a ClientErrorException with cause.- Parameters:
statusCode- the HTTP status code (4xx)message- descriptive error messagerequest- the original HTTP requestresponse- the HTTP responsecause- the underlying cause
-
-
Method Details
-
isRetryable
public boolean isRetryable()Client errors are generally not retryable, except for 429 Too Many Requests.- Overrides:
isRetryablein classHttpException- Returns:
- true only if status code is 429 (rate limiting)
-
isBadRequest
public boolean isBadRequest()Check if this is a 400 Bad Request error.- Returns:
- true if status code is 400
-
isUnauthorized
public boolean isUnauthorized()Check if this is a 401 Unauthorized error. Usually indicates missing or invalid API key.- Returns:
- true if status code is 401
-
isForbidden
public boolean isForbidden()Check if this is a 403 Forbidden error. Usually indicates valid auth but insufficient permissions.- Returns:
- true if status code is 403
-
isNotFound
public boolean isNotFound()Check if this is a 404 Not Found error.- Returns:
- true if status code is 404
-
isMethodNotAllowed
public boolean isMethodNotAllowed()Check if this is a 405 Method Not Allowed error.- Returns:
- true if status code is 405
-
isConflict
public boolean isConflict()Check if this is a 409 Conflict error.- Returns:
- true if status code is 409
-
isUnprocessableEntity
public boolean isUnprocessableEntity()Check if this is a 422 Unprocessable Entity error. Usually indicates validation errors.- Returns:
- true if status code is 422
-
isTooManyRequests
public boolean isTooManyRequests()Check if this is a 429 Too Many Requests error. This error is retryable after waiting for the rate limit to reset.- Returns:
- true if status code is 429
-
getRetryAfterMs
public long getRetryAfterMs()Get the retry-after delay in milliseconds from response headers. This is typically provided with 429 responses.- Returns:
- the retry delay in milliseconds, or -1 if not available
-