Skip to content
QwryAI
Documentation
Pages

Android SDK

Error Handling

The one exception the QwryAI Android SDK throws, its codes and how to handle them

One exception type

Every failure the SDK reports is a QwryException. Its code tells you what went wrong, and its status tells you whether the server refused the request or the SDK gave up on its own:

Code
QwryException
├── status != null   the server answered with an error (HTTP status)
└── status == null   the SDK's own codes: NETWORK_ERROR, INVALID_RESPONSE, TOOL_LOOP_LIMIT_EXCEEDED

QwryException

class QwryException : Exception, Package: com.qwryai.sdk

Kotlin
class QwryException(
    val status: Int?,
    val code: String,
    message: String,
    val details: Map<String, String>? = null
) : Exception(message)

status Int?

The HTTP status of the server's error response, such as 401, 403 or 429. null for the SDK's own codes.

code String required

A stable, machine-readable code. Use it in your logic.

message String required

A readable description, from the server or the SDK.

details Map<String, String>?

Field-by-field reasons when a request failed validation, such as cursor → Invalid cursor.

Convenience properties

Kotlin
val isRateLimited: Boolean      // status == 429
val isNotFound: Boolean         // status == 404
val isCreditsExhausted: Boolean // status == 402

The SDK's own codes

Kotlin
QwryException.NETWORK_ERROR            // The request never got an answer
QwryException.INVALID_RESPONSE         // The server sent something the SDK could not read
QwryException.TOOL_LOOP_LIMIT_EXCEEDED // The agent called tools more than maxToolLoopSteps times in a row

Error codes

These are the codes you can meet in QwryException.code:

StatusCodeWhen
400VALIDATION_INVALID_BODYThe request failed validation; details names the field. Also returned for a tool result over 20 KB and for a cursor the server didn't issue.
400CHAT_RETRY_NO_USER_MESSAGEThe message passed to retry() has no user message before it.
401AUTH_INVALID_JWTThe token passed to identify(), or the one stored from it, is invalid or expired, or the agent has no identity verification secret. See User Identity.
402CHAT_CREDITS_EXHAUSTEDThe workspace has no message credits left. Caught by isCreditsExhausted.
403AUTH_OWNERSHIP_MISMATCHThe conversation belongs to another device or user, or doesn't exist. Also returned by retry() and listMessages() for an unknown conversation.
403CHAT_CONVERSATION_MISMATCHThe conversation belongs to a different agent.
403CHAT_CONVERSATION_NOT_ONGOINGThe conversation has ended or a person has taken it over, or another answer or client-side action is still in progress in it. Start a new conversation, or wait and try again.
403ACCESS_COUNTRY_BLOCKEDThe agent blocks requests from the user's country.
404AGENT_NOT_FOUNDNo agent has this ID, or the Android SDK channel's Visibility is off. See Quick start. Caught by isNotFound.
404CHAT_RETRY_MESSAGE_NOT_FOUNDThe message passed to retry() isn't in the conversation. Caught by isNotFound.
404RESOURCE_TOOL_CALL_NOT_FOUNDThe tool call wasn't found or has expired. Can surface from the automatic tool loop. Caught by isNotFound.
404RESOURCE_TOOL_CALL_MISMATCHThe tool call belongs to another conversation. Caught by isNotFound.
404RESOURCE_TOOL_RESULT_NOT_PENDINGThe tool's result was already sent. Caught by isNotFound.
429RATE_LIMIT_TOO_MANY_REQUESTSMore than 1,000 requests in 10 seconds from this install. Wait and try again. Caught by isRateLimited.
500CHAT_STREAMING_ERRORThe answer failed while it was streaming. Safe to retry.
500INTERNAL_SERVER_ERRORSomething unexpected went wrong on the server. Try again, and contact us if it keeps happening.
noneNETWORK_ERRORNo answer: no connection, a DNS failure or a timeout.
noneINVALID_RESPONSEThe server's response couldn't be read.
noneTOOL_LOOP_LIMIT_EXCEEDEDThe agent kept calling tools past maxToolLoopSteps (10 by default).

Handling errors

Wrap calls in try/catch:

Kotlin
try {
    val response = client.send("Hello")
} catch (e: QwryException) {
    when {
        e.code == QwryException.NETWORK_ERROR -> {
            println("No connection. Check the network and try again.")
        }
        e.status == 401 -> {
            println("Sign-in expired. Get a new token from your server.")
        }
        e.status == 403 -> {
            println("Access denied: ${e.code}")
        }
        e.isRateLimited -> {
            println("Too many requests. Wait and retry.")
        }
        e.isCreditsExhausted -> {
            println("No message credits left.")
        }
        e.isNotFound -> {
            println("Not found. Check the agent ID and the channel's Visibility.")
        }
        else -> {
            println("Error: ${e.code}: ${e.message}")
        }
    }
}

Explore the documentation