Class LlmException
java.lang.Object
java.lang.Throwable
java.lang.Exception
java.io.IOException
com.codename1.ai.LlmException
The single checked-error type raised by LlmClient. Extends
IOException so callers' existing network catch blocks pick it
up. Inspect getType() for the failure category and switch on
the LlmException.ErrorType enum -- no separate exception subclass per error.
try {
ChatResponse r = client.chat(req).get();
// ...
} catch (AsyncExecutionException ae) {
if (ae.getCause() instanceof LlmException) {
LlmException e = (LlmException) ae.getCause();
switch (e.getType()) {
case RATE_LIMIT: scheduleRetry(e.getRetryAfterSeconds()); break;
case AUTH: showLoginScreen(); break;
case CONTEXT_LENGTH: trimHistory(); break;
case MODEL_OVERLOADED: scheduleRetry(60); break;
case INVALID_REQUEST: showError(e); break;
case NETWORK: showOfflineUi(); break;
default: showError(e);
}
}
}
httpStatus, providerErrorCode, rawBody, and (for rate-limit
errors) retryAfterSeconds are populated when the provider
returned them. getRetryAfterSeconds() returns -1 for every
non-rate-limit error and for rate-limit errors where the provider
didn't send a Retry-After header.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumCoarse-grained classification of every failure path the client can surface. -
Constructor Summary
ConstructorsConstructorDescriptionLlmException(String message) Creates an unclassified provider failure.LlmException(String message, int httpStatus, String providerErrorCode, String rawBody, Throwable cause, LlmException.ErrorType type) Creates a classified provider failure without retry timing.LlmException(String message, int httpStatus, String providerErrorCode, String rawBody, Throwable cause, LlmException.ErrorType type, int retryAfterSeconds) Creates a fully classified provider failure.LlmException(String message, Throwable cause) Creates an unclassified failure with its underlying cause. -
Method Summary
Modifier and TypeMethodDescriptionintintSeconds the provider asked us to wait before retrying, parsed from aRetry-Afterheader.getType()Coarse-grained category -- the recommended switching point for error handling.Methods inherited from class Throwable
addSuppressed, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, setStackTrace, toString
-
Constructor Details
-
LlmException
Creates an unclassified provider failure.- Parameters:
message- user-readable failure description
-
LlmException
-
LlmException
public LlmException(String message, int httpStatus, String providerErrorCode, String rawBody, Throwable cause, LlmException.ErrorType type) Creates a classified provider failure without retry timing.- Parameters:
message- user-readable failure descriptionhttpStatus- HTTP status, or-1without a responseproviderErrorCode- provider-specific machine coderawBody- raw response body retained for diagnosticscause- originating error, ornulltype- portable failure classification
-
LlmException
public LlmException(String message, int httpStatus, String providerErrorCode, String rawBody, Throwable cause, LlmException.ErrorType type, int retryAfterSeconds) Creates a fully classified provider failure.- Parameters:
message- user-readable failure descriptionhttpStatus- HTTP status, or-1without a responseproviderErrorCode- provider-specific machine coderawBody- raw response body retained for diagnosticscause- originating error, ornulltype- portable failure classificationretryAfterSeconds- server-requested delay, or-1
-
-
Method Details
-
getType
Coarse-grained category -- the recommended switching point for error handling. See the class javadoc for the full pattern. -
getHttpStatus
public int getHttpStatus()- Returns:
- HTTP status, or
-1when no response was received
-
getProviderErrorCode
- Returns:
- provider-specific error code, or
null
-
getRawBody
- Returns:
- raw response body for diagnostics, or
null
-
getRetryAfterSeconds
public int getRetryAfterSeconds()Seconds the provider asked us to wait before retrying, parsed from aRetry-Afterheader.-1when not applicable (the usual case for non-RATE_LIMITerrors) or when the provider did not send the header.
-