SquareCloudAPIError.
Examples use the api client from Creating the client. appId is the id of one of your apps: api.account.me() lists them.
SquareCloudAPIError
SquareCloudAPIError extends Error (it is not a TypeError).
Two failures are not wrapped:
- An aborted call rejects with the signal’s
reason. An abortedrealtime()loop just ends. - An upload path that cannot be opened throws the file system error.
SDK codes
The messages of
TIMEOUT, FILE_TOO_LARGE and INVALID_ID, like the TypeError of an empty API key, say what happened and how to fix it. They were rewritten in 6.1.0, so match on code, never on the message text.
The ErrorCode type
ErrorCode is a type only (no runtime object). It lists every public API code, the deprecated ones and the SDK’s, plus string & {}, so your editor autocompletes known codes and new codes still type-check. RATE_LIMIT and RATE_LIMIT_EXCEEDED are still in the type, marked deprecated: the API now answers RATE_LIMITED for both.
METRICS_NOT_SUPPORTED is deprecated too, because every app now has metrics. Version 6.1.0 added AI_WEEKLY_LIMIT_REACHED, ENV_BUSY, GIT_BRANCH_DELETED, GIT_REF_NOT_SUPPORTED, RESTORE_INTERRUPTED, SNAPSHOT_CORRUPT, SNAPSHOT_IN_PROGRESS, SNAPSHOT_RESTORE_PROCESSING, SNAPSHOTS_UNAVAILABLE, WRITE_FAILED and WRONG_HOST. Two of them never reach your code: a 202 SNAPSHOT_RESTORE_PROCESSING resolves restore() to { pending: true } (see Snapshots), and no SDK method receives 421 WRONG_HOST.
The list of API codes grows. Handle an unknown code by its HTTP status:
API error codes
Every other code comes from the API. The API error reference lists each one with its HTTP status, meaning and fix, and each SDK page lists the codes its methods return most often. Any call can also answer 401ACCESS_DENIED (a bad key), 403 MISSING_SCOPE or RESOURCE_NOT_ALLOWED (the limits of the key), 429 (see Rate limits) or 503 DATABASE_UNAVAILABLE.
ai.chat() errors use lowercase OpenAI codes instead (access_denied, rate_limit_exceeded, server_overloaded, …). See AI.
Retries
The SDK only retries what is safe to repeat, up tomaxRetries times (default 2, so up to 3 attempts):
It never retries:
TIMEOUT;- any 429:
RATE_LIMITEDcan be a block of about 30 minutes, andKEEP_CALMis not retried either; - the 409 of a busy resource:
RESTORE_IN_PROGRESSandSNAPSHOT_IN_PROGRESSwhile a restore or a snapshot runs, andENV_BUSYfromenvs.set,envs.replaceandenvs.deletewhile another request changes the variables. Try again when the other operation ends; - 503
SNAPSHOTS_UNAVAILABLEfrom the snapshot listings (try again in about 30 seconds) and 503CLUSTER_MAINTENANCE_TRY_LATERfrom snapshotcreateandrestore; - other 5xx;
- AI errors.
DATABASE_UNAVAILABLE can arrive after a mutation was already applied, so the SDK does not retry it outside GET. Retry your own idempotent mutations if you need to.
The wait before retry n (starting at 0) is min(8 s, 500 ms · 2^n) · U(0.5, 1): exponential backoff with 50% to 100% jitter. Set maxRetries: 0 to turn retries off.
Timeouts
timeoutMs (30 s) applies per attempt and covers the whole response. See Timeouts for the calls with a 120 s floor and the calls with no timeout. A timeout throws TIMEOUT with status 0 and is never retried.
Rate limits
Every account has a limit of requests per 60 seconds, set by its plan (values), and some routes have their own:- 429
RATE_LIMITED: the account or API key went over its request budget and is blocked for about 30 minutes, or an IP that keeps sending invalid keys is blocked for a short period. Also the limit of the network endpoints andaccount.snapshots. - 429
KEEP_CALM: too many calls to one route in a short time.
Next steps
API error reference
Every error code, with its meaning and fix.
Limits and restrictions
The request limits of each plan.

