public class LlmException

  1. Object
  2. Throwable
  3. Exception
  4. IOException
  5. 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 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 types

enum LlmException.ErrorTypeCoarse-grained classification of every failure path the client can surface.

Constructors

public LlmException(String message)Creates an unclassified provider failure.
public LlmException(String message, Throwable cause)Creates an unclassified failure with its underlying cause.
public LlmException(String message, int httpStatus, String providerErrorCode, String rawBody, Throwable cause, LlmException.ErrorType type)Creates a classified provider failure without retry timing.
public LlmException(String message, int httpStatus, String providerErrorCode, String rawBody, Throwable cause, LlmException.ErrorType type, int retryAfterSeconds)Creates a fully classified provider failure.

Methods

public LlmException.ErrorType getType()Coarse-grained category – the recommended switching point for error handling.
public int getHttpStatus()
public String getProviderErrorCode()
public String getRawBody()
public int getRetryAfterSeconds()Seconds the provider asked us to wait before retrying, parsed from a Retry-After header.

Inherited methods

Constructor details

LlmException

public LlmException(String message)
Creates an unclassified provider failure.

Parameters

message String
user-readable failure description

LlmException

public LlmException(String message, Throwable cause)
Creates an unclassified failure with its underlying cause.

Parameters

message String
user-readable failure description
cause Throwable
network, parsing, or provider cause

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 String
user-readable failure description
httpStatus int
HTTP status, or -1 without a response
providerErrorCode String
provider-specific machine code
rawBody String
raw response body retained for diagnostics
cause Throwable
originating error, or null
type LlmException.ErrorType
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 String
user-readable failure description
httpStatus int
HTTP status, or -1 without a response
providerErrorCode String
provider-specific machine code
rawBody String
raw response body retained for diagnostics
cause Throwable
originating error, or null
type LlmException.ErrorType
portable failure classification
retryAfterSeconds int
server-requested delay, or -1

Method details

getType

public LlmException.ErrorType 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 -1 when no response was received

getProviderErrorCode

public String getProviderErrorCode()

Returns

provider-specific error code, or null

getRawBody

public String getRawBody()

Returns

raw response body for diagnostics, or null

getRetryAfterSeconds

public int getRetryAfterSeconds()
Seconds the provider asked us to wait before retrying, parsed from a Retry-After header. -1 when not applicable (the usual case for non-RATE_LIMIT errors) or when the provider did not send the header.