The embedded engine raises subclasses of SirannonError, each with a code that a program can compare, while the network client raises RemoteError when the server refuses a call. Match on code, because the diagnostic messages can change between releases. The example below catches a failed NOT NULL constraint and closes the registry whichever error occurs.
import { mkdtemp, rm } from 'node:fs/promises'
import { tmpdir } from 'node:os'
import { join } from 'node:path'
import { QueryError, Sirannon } from '@delali/sirannon-db'
import { betterSqlite3 } from '@delali/sirannon-db/driver/better-sqlite3'
const directory = await mkdtemp(join(tmpdir(), 'sirannon-errors-'))
const sirannon = new Sirannon({ driver: betterSqlite3() })
try {
const db = await sirannon.open('shop', join(directory, 'shop.db'))
await db.execute('CREATE TABLE orders (id INTEGER PRIMARY KEY, total REAL NOT NULL)')
try {
await db.execute('INSERT INTO orders (id) VALUES (?)', [1])
} catch (error) {
if (!(error instanceof QueryError)) throw error
console.error(`SQL failed [${error.code}]: ${error.message}`, error.sql)
}
} finally {
try {
await sirannon.shutdown()
} finally {
await rm(directory, { recursive: true, force: true })
}
}Some errors have fields beside the code:
QUERY_ERRORhassql.CONFLICT_ERRORhastable,rowId, andcause.- A migration error has
version. WRITE_OVERLOADEDhaslimitandretryAfterMs.SYNC_ERRORhasrequestId.MIGRATION_REQUIREDandSCHEMA_AHEADhaveserverVersion.
Every HTTP error response contains the error object below, while every WebSocket error message contains the same object beside its message type and request ID. The server adds details only when it has context that it can share.
{ "error": { "code": "ERROR_CODE", "message": "Human-readable description", "details": {} } }A dash in a class column below means that Sirannon raises the base SirannonError with that code, so match on err.code for those codes.
Before it replies over HTTP or WebSocket, the server replaces the message of a file-opening, extension, optional-dependency, row-count, or encryption error with a fixed message that contains no file paths, and it sends no details with that message. It does the same for EXECUTION_TIMEOUT_UNSUPPORTED, BACKUP_ERROR, and BACKUP_DESTINATION_ERROR, whose messages can contain paths on the server. The server sends a fixed message without details for EXECUTION_TIMEOUT as well, because SQLite words that error differently depending on where it stops the statement. The error in the server process contains the full diagnostic context.
Core engine
| Class | Code | When |
|---|---|---|
DatabaseNotFoundError | DATABASE_NOT_FOUND | Neither the registry nor a lifecycle resolver can provide a database for the ID. |
DatabaseAlreadyExistsError | DATABASE_ALREADY_EXISTS | A caller registers an ID that another database uses. |
| - | DATABASE_CLOSED | A caller uses a database after the database closes. |
| - | DATABASE_OPEN_FAILED | SQLite can't open the database file, as it does when the directory of the file is missing. |
ReadOnlyError | READ_ONLY | A caller sends a write, or opens a live query, on a read-only database. |
QueryError | QUERY_ERROR | SQLite fails to prepare or execute a statement, on this node or, for a forwarded write, on the primary. |
| - | INVALID_READ_LIMIT | A caller passes queryWithColumns a maxRows or a maxBytes other than a whole number from 0 to 2^53-1. |
| - | COLUMN_DETAILS_UNSUPPORTED | A caller calls queryWithColumns on a driver whose columnDetails capability is false. On Bun, a read through queryWithColumns with maxRows or maxBytes that returns two columns of the same name fails with this code too. |
ForbiddenSqlError | FORBIDDEN_SQL | A statement refers to a _sirannon table, whether bare, in double quotes, backticks, or square brackets, or as a single-quoted string where SQLite reads a table name, as in FROM '_sirannon_meta'. Sirannon also raises the code for a statement that modifies the sqlite_ catalogue, uses ATTACH, DETACH, or VACUUM INTO, or uses the writable_schema, temp_store_directory, data_store_directory, or wal_checkpoint pragma. It raises the code as well for BEGIN, COMMIT, END, ROLLBACK, SAVEPOINT, and RELEASE, and for a CREATE or a DROP of a temporary table, view, index, or trigger, whether the statement is in a call or in a pending migration. Call checkpoint() in place of PRAGMA wal_checkpoint, and transaction() or executeTransaction() in place of BEGIN and COMMIT. |
TransactionError | TRANSACTION_ERROR | Every statement in a transaction succeeds and SQLite then refuses the commit, as it does when a deferred foreign key fails at the commit. The error's cause contains SQLite's error. |
| - | TRANSACTION_CLOSED | A caller uses a transaction handle after its callback returns or throws. |
| - | WRITER_HELD_BY_CALLBACK | On wa-sqlite or Expo, a transaction callback makes a call through the database while the callback holds the writer. Use the tx handle of that callback. |
HookDeniedError | HOOK_DENIED | A before-hook rejects the operation. |
RequestDeniedError | a caller-defined code | The authenticate hook refuses the request with a caller-defined status and code. |
CDCError | CDC_ERROR | The change-data-capture pipeline fails, or Sirannon cannot use a statement for a live query. |
BackupError | BACKUP_ERROR | A backup fails for a reason without a more specific code, such as a refused path or an invalid piece size. |
| - | BACKUP_UNSUPPORTED | The driver provides no backup engine, the connection offers no stepped copy call, the node driver uses a Node.js build whose node:sqlite exports no backup function, or a database configures backups without a file in write-ahead logging mode. |
| - | BACKUP_RESTARTED | SQLite returns the copy to page one more times than restartLimit allows, or the copy reaches no new page across noProgressStepLimit steps. |
| - | BACKUP_STALLED | The copy completes no step inside stallTimeoutMs, including a copy that the writer worker stops part-way. |
| - | BACKUP_DESTINATION_ERROR | Your destination refuses a call, fails to answer inside destinationTimeoutMs, or returns pieces that do not match their chain metadata. |
| - | BACKUP_LOG_REWOUND | The write-ahead log restarts before a capture copies its frames, so the backup chain has a gap. |
| - | BACKUP_CHAIN_BROKEN | No full copy goes back as far as the requested moment, a chain is missing a piece that a restore needs, or no chain record has the name that the caller passes to verifyBackup. |
ConnectionPoolError | CONNECTION_POOL_ERROR | The pool is closed, exhausted, or misconfigured. |
MaxDatabasesError | MAX_DATABASES | A caller opens more databases than the configured cap allows. |
ExtensionError | EXTENSION_ERROR | Sirannon cannot load a native SQLite extension. |
| - | INVALID_DRIVER | The driver configuration fails validation. |
| - | ROW_COUNTS_UNSUPPORTED | The driver requests row counts, but the required native package or a usable counting build is missing. |
ExecutionTimeoutError | EXECUTION_TIMEOUT | SQLite stops a statement at the call's executionTimeoutMs, after which Sirannon rolls back the call's transaction, so the database contains none of the call's writes. Sirannon raises the code for every later statement of that transaction as well. |
| - | INVALID_EXECUTION_TIMEOUT | A caller passes an executionTimeoutMs other than a whole number from 1 to 2,147,483,647. |
| - | EXECUTION_TIMEOUT_UNSUPPORTED | A caller passes executionTimeoutMs on a driver whose executionTimeouts capability is false. The better-sqlite3 driver also fails open with this code under executionTimeouts: true when it can't load a build of @delali/sirannon-sqlite that interrupts statements. |
| - | INVALID_SYNCHRONOUS | A caller supplies an unknown synchronous level. |
| - | INVALID_DURABILITY | A load passes a durability other than 'off' or 'normal'. |
| - | DURABILITY_RESTORE_FAILED | Sirannon fails to restore the configured durability. It refuses later writes while restoration continues to fail. |
| - | BULK_LOAD_IN_TRANSACTION | A transaction callback calls bulkLoad. Use tx.executeBatch to write the rows inside a transaction. |
| - | CHECKPOINT_IN_TRANSACTION | A transaction callback calls checkpoint, which SQLite can't carry out inside a transaction, so call it once the transaction ends. |
| - | SNAPSHOT_IN_PROGRESS | A caller sends a read or a write while a device-sync snapshot load replaces the database. |
| - | SHUTDOWN | A caller starts an operation after the registry shuts down. |
| - | SHUTDOWN_ERROR | One or more databases fail to close during shutdown. |
| - | LIFECYCLE_DISPOSED | A caller resolves a database after the application disposes the lifecycle manager. |
| - | INTERNAL_SCHEMA_ERROR | An internal-table identifier, column type, or default fails validation, or a schema version falls outside PRAGMA user_version. |
Encryption
EncryptionError extends SirannonError. The encryption guide explains key storage, file replacement, and recovery.
| Code | When |
|---|---|
ENCRYPTION_UNSUPPORTED | The driver, native build, runtime, or required Expo filesystem cannot provide the requested encryption operation. |
INVALID_ENCRYPTION_KEY | The loader returns something other than exactly 32 raw bytes, directly or as { key, id }. |
ENCRYPTION_KEY_UNAVAILABLE | The loader throws or rejects, in which case the error's cause contains that failure. |
ENCRYPTION_KEY_MISSING | A caller opens an encrypted file without a key. |
ENCRYPTION_KEY_REJECTED | The key fails to decrypt the first page, or the file uses another cipher. |
DATABASE_NOT_ENCRYPTED | A caller opens a plaintext file with a key. Use changeEncryption to encrypt the file. |
ENCRYPTED_PAGE_CORRUPT | A later page fails authentication. |
ENCRYPTION_REQUIRED | A plaintext peer requests changes or a snapshot from an encrypted node. |
ENCRYPTION_CHANGE_IN_PROGRESS | Another change is active, or an engine starts while a change replaces the file. |
ENCRYPTION_CHANGE_ABORTED | A schema change or a write prevents an exact copy, so Sirannon goes on using the original file. |
A key change can finish with state: 'done' and reopenError. Sirannon uses the new file and key from that point, so retain that key and reopen the database with it. An aborted change, by contrast, leaves the original file in use.
Writer worker
The writer worker reports a rejected write with a different code from a write whose outcome is unknown, so you can tell when a retry is safe and when you have to reconcile first.
| Code | When | Retry? |
|---|---|---|
WRITE_OVERLOADED | More writes are pending than maxPendingWrites allows, or the worker sheds a queued write when an earlier deadline expires. The server answers HTTP with 503 and Retry-After. | Retry, because Sirannon never applies the write. |
WRITER_WORKER_TIMEOUT | The writer reports no outcome within twice writeTimeoutMs. | Retry only after you reconcile, because the outcome is indeterminate. |
WRITER_WORKER_EXIT | The worker crashes or exits. An active callback transaction rolls back, so later statements in that callback fail too. | Reconcile an ordinary in-flight write before you retry, because the write can commit before the crash. |
WRITER_WORKER_FATAL | The writer passes its restart budget, so every later write fails. | Restart the process, because every retry fails. |
WRITER_WORKER_UNAVAILABLE | A caller sends a write while no writer is available. | Retry, because the write never reaches the writer. |
WRITER_WORKER_CLOSED | A caller sends a write after the writer closes, or the writer closes while the write is in flight. | Reconcile first when the write is in flight. |
WRITER_WORKER_POST_FAILED | The host cannot pass the operation to the writer. | Retry, because the write never reaches the writer. |
WRITER_WORKER_NO_PORT | The writer entry point starts outside a worker thread. | Fix the configuration, because every retry fails. |
WRITER_WORKER_UNSUPPORTED | A caller enables writerWorker on a driver with no worker entry, so Sirannon refuses to open the database. | Change the driver or the option, because every retry fails. |
INVALID_WRITER_WORKER | A writerWorker value is out of range. | Fix the configuration, because every retry fails. |
Backups
Before you retry a backup, check the staged captures, because Sirannon removes a partial local copy once the copy operation stops. A destination that follows the contract supports safe replacement of an ordinary piece on a later capture.
| Code | Retry? |
|---|---|
BACKUP_RESTARTED | Retry once the connection that writes to the source file stops. Sirannon removes the partial file, because the copy stores nothing usable. |
BACKUP_STALLED | Retry, because Sirannon removes the partial file once SQLite stops writing it. |
BACKUP_DESTINATION_ERROR | Retry once your storage answers again. A cycle leaves the capture staged and sends it again on a later turn automatically. |
BACKUP_LOG_REWOUND | A retry fails, because the backup chain has a gap. The cycle starts a fresh chain with a full copy. |
BACKUP_CHAIN_BROKEN | Ask for a moment that an intact chain reaches, or let the cycle start a fresh chain, because a retry of the same moment fails. |
BACKUP_UNSUPPORTED | Change the driver, the runtime, or the options of the database, because every retry fails. |
BACKUP_RESTORE_IN_PROGRESS | Retry once the active restore finishes. |
BACKUP_RESTORE_NOT_ACCEPTED | The operator has to turn the route on with acceptBackupRestore before a retry can succeed. |
Migrations
| Code | When |
|---|---|
MIGRATION_ERROR | A migration step fails as it executes. Sirannon also raises it when a migration that turns foreign keys off leaves a row without its parent row, which PRAGMA foreign_key_check finds before the commit. |
MIGRATION_VALIDATION_ERROR | A migration definition fails validation, as a string migration does when it sets withoutForeignKeys and its up SQL lacks PRAGMA foreign_keys = OFF. |
MIGRATION_DUPLICATE_VERSION | Two migrations share a version. |
MIGRATION_NO_DOWN | A caller rolls back a migration with no down statement. |
MIGRATION_SOURCE_INVALID | The registry migration source returns something other than a list. |
MIGRATION_CHECKSUM_MISMATCH | An applied migration's stored checksum differs from the checksum of its current SQL. |
MIGRATION_BASELINE_GAP | A history below a baseline lacks the bridging migrations. |
MIGRATION_CONCURRENT | Concurrent migration work prevents Sirannon from applying a migration safely. |
MIGRATION_ROLLBACK_ERROR | A rollback step fails. |
Server and requests
| Code | When |
|---|---|
INVALID_REQUEST | The request body has an invalid structure, as a query body does when it sets shape to a value other than columns, sets a limit outside the range from 0 to 2^53-1, or sets maxRows or maxBytes without shape. |
INVALID_JSON | The body or WebSocket message is not valid JSON. |
EMPTY_BODY | The request body is empty. |
PAYLOAD_TOO_LARGE | The body or message exceeds maxBodyBytes. |
INTERNAL_ERROR | An unexpected error occurs while the server handles the request. |
HOOK_ERROR | The authenticate hook returns a refusal object, or it throws without a valid status, code, and message. The cluster-status authoriser can raise this code as well. |
NOT_FOUND | The route does not exist, or the server has no cluster status or refuses it to the caller. |
INVALID_MAX_BODY_BYTES | maxBodyBytes is not a positive integer that the transport can enforce exactly. |
INVALID_WS_BACKPRESSURE | maxWebSocketBackpressureBytes fails validation or falls below maxBodyBytes. |
INVALID_CLOSE_TIMEOUT | server.close receives a timeout outside the whole-number range from 0 to 2,147,483,647. |
INVALID_ENCRYPTION_CHANGE | You enable key changes without authenticate or an encryptionKeys resolver. |
ENCRYPTION_CHANGE_NOT_ACCEPTED | A caller reaches the change route while acceptEncryptionChange is off. |
INVALID_BACKUP_RESTORE | acceptBackupRestore is true and the server has no authenticate hook, so createServer refuses to create the server. |
INVALID_DEVICE_SYNC | acceptDeviceSync is true and the server has no authenticate hook, so createServer refuses to create the server. |
BACKUP_RESTORE_NOT_ACCEPTED | A caller reaches POST /db/:id/backup/restore on a server that leaves acceptBackupRestore off. |
BACKUP_RESTORE_IN_PROGRESS | A restore of that database is in progress. |
BULK_LOAD_UNSUPPORTED | The execution target provides no bulk load. |
INVALID_MESSAGE | A WebSocket message lacks a required field or contains a value of the wrong type, as a query message does when it contains name together with shape, maxRows, or maxBytes. |
UNSUPPORTED_SUBPROTOCOL | A WebSocket upgrade offers subprotocols without sirannon.v1. |
UNKNOWN_TYPE | A WebSocket message specifies an unrecognised type. |
HANDLER_CLOSED | The WebSocket handler is shutting down. |
DUPLICATE_SUBSCRIPTION | A subscription with the same ID exists on the connection. |
SUBSCRIPTION_NOT_FOUND | A caller unsubscribes from a subscription that does not exist. |
CDC_UNSUPPORTED | A caller subscribes to an in-memory database, because subscriptions require a file-based database. |
Registered operations
These codes describe failures in registered operations.
| Code | When |
|---|---|
UNKNOWN_QUERY | The database has no registered operation of that name. |
MISSING_ARGUMENT | A declared argument is absent from the request. |
ARGUMENT_NOT_ALLOWED | The caller supplies an undeclared argument, or one that the server fills from identity. |
IDENTITY_REQUIRED | An operation fills an argument from identity and the request supplies none. |
REGISTRY_MISMATCH | A live query sends a registry digest that differs from the digest of this server. |
SQL_NOT_ACCEPTED | The server accepts no SQL over the network, or it refuses a subscription to a table's changes because acceptSql is false and its registry has no onBeforeSubscribe hook. |
Replication
@delali/sirannon-db/replication exports every class in this table. FailoverError is the shared base of NoSafePrimaryError and UnsafeRecoveryRequiredError.
| Class | Code | When |
|---|---|---|
ReplicationError | REPLICATION_ERROR | Every other class in this table extends this base class for replication failures. |
SyncError | SYNC_ERROR | The first sync fails because the node is not ready, the transfer times out, or a manifest or batch order does not match. |
ConflictError | CONFLICT_ERROR | A conflict resolver throws while Sirannon applies a change. table and rowId identify the row, and cause contains the resolver's error. |
TransportError | TRANSPORT_ERROR | A peer is unreachable or a send fails. A primary that refuses a forwarded write with a Sirannon code, such as QUERY_ERROR for a statement that SQLite rejects, sends that code back to the replica unchanged. |
BatchValidationError | BATCH_VALIDATION_ERROR | A batch fails its checksum, breaks the schema allowlist, exceeds maxClockDriftMs, or includes unsafe DDL. |
WriteConcernError | WRITE_CONCERN_ERROR | The group does not meet the write concern inside the timeout. |
ReadConcernError | READ_CONCERN_ERROR | The node cannot satisfy the requested read concern. |
TopologyError | TOPOLOGY_ERROR | A replica refuses a write, no primary is available, a node is outside group membership, a peer is unauthorised, or a coordinator-mode configuration includes endpoint lists. |
CoordinatorError | COORDINATOR_UNAVAILABLE | The node cannot reach the coordinator, or the coordinator cannot prove quorum authority. |
AuthorityError | AUTHORITY_LOST | A node loses primary or controller authority while it handles work. |
StalePrimaryError | STALE_PRIMARY | A request, batch, sync message, or forwarded write uses a stale primary term. |
NoSafePrimaryError | NO_SAFE_PRIMARY | The controller finds no eligible in-sync replica that it can promote safely. |
NodeNotInSyncError | NODE_NOT_IN_SYNC | The node is alive but outside the group's in-sync set. |
NodeDrainingError | NODE_DRAINING | The node is in maintenance drain mode. |
ProtocolVersionMismatchError | PROTOCOL_VERSION_MISMATCH | Node compatibility metadata is incompatible with the cluster, or the group's feature level is higher than the node supports. |
UnsafeRecoveryRequiredError | UNSAFE_RECOVERY_REQUIRED | Recovery requires an explicit operator action. |
ReplicationError | REPLICATION_ACTIVE | A key change or restore targets a file that an active replication engine uses. |
Device sync
| Code | When |
|---|---|
MIGRATION_REQUIRED | The device schema version is behind the server, so the device has to migrate before it syncs. |
SCHEMA_AHEAD | The device schema version is ahead of the server, so the server has to migrate first. |
SYNC_UNSUPPORTED | The execution target applies no changes, or the server predates device sync. |
SNAPSHOT_UNSUPPORTED | A device requests a snapshot of an in-memory database. |
SNAPSHOT_CHECKSUM_MISMATCH | A downloaded snapshot page fails checksum verification. |
DEVICE_SYNC_NOT_ACCEPTED | The server leaves acceptDeviceSync off, so it serves no device sync. SyncController.start() raises the same code against such a server. |
DEVICE_CLOCK_AHEAD | A pushed change has a stamp more than 300,000 milliseconds ahead of the server clock. The device stores those writes and pushes them again later. |
DEVICE_NOT_SUBSCRIBED | An acknowledgement specifies a device with no subscription on that connection. |
Optional packages
Sirannon raises these codes in the local process when it starts a server, a replication transport, or a coordinator whose package it cannot load. The message identifies the missing package and the command that installs it.
| Code | When |
|---|---|
SERVER_DEPENDENCY_MISSING | server.listen() cannot load uWebSockets.js. |
TRANSPORT_DEPENDENCY_MISSING | The gRPC transport cannot load @grpc/grpc-js, @bufbuild/protobuf, or grpc-health-check as the engine starts. |
COORDINATOR_DEPENDENCY_MISSING | The etcd coordinator cannot load etcd3 when the engine first calls it. |
Client
| Code | When |
|---|---|
CONNECTION_ERROR | The client fails to connect to the server. |
UNAUTHORIZED | The server refuses the WebSocket upgrade as unauthenticated and closes with 4401. |
FORBIDDEN | The server refuses the WebSocket upgrade as not permitted and closes with 4403. |
TIMEOUT | A WebSocket request or a checkpoint exceeds the configured requestTimeout. |
TRANSPORT_ERROR | The transport cannot provide the operation, or the caller closes it before the request finishes. |
INVALID_RESPONSE | The response is invalid JSON or has another structure than the client expects, as a column answer does when a row is wider or narrower than its columns, or when a value contains an integer outside the 64-bit range of SQLite or a malformed BLOB. |
ROUTING_ERROR | Topology routing finds no usable primary or read endpoint. |
NO_SAFE_PRIMARY | Topology routing in coordinator mode finds no current primary for a write or a linearizable read. |
INVALID_ARGUMENT | A client argument fails validation, such as a read concern on a single call through the topology transport, or a maxRows or maxBytes outside the range from 0 to 2^53-1, which the client refuses before it sends the request. |
UNKNOWN_ERROR | An error response includes no recognisable code. |
Deciding whether to retry
Retry each of these three groups in a different way, because a retry loop that treats them alike can apply a write twice.
- Definite rejections are safe to send again.
WRITE_OVERLOADEDmeans that Sirannon sheds the write without applying it. The server includesRetry-Afterin the HTTP response for that code.WRITER_WORKER_UNAVAILABLEandWRITER_WORKER_POST_FAILEDreport the same about a write that never reaches the writer.EXECUTION_TIMEOUTmeans that Sirannon rolls back every write of the call, so you can retry the call without applying a write twice, although SQLite can stop the same statement again under the same limit. - Indeterminate outcomes need reconciling first.
WRITER_WORKER_TIMEOUTandWRITER_WORKER_EXITleave the outcome unknown, so read the state back before you resend anything that is not idempotent. - Routing failures can require fresh cluster metadata. The topology client refreshes its metadata after
STALE_PRIMARY,AUTHORITY_LOST,COORDINATOR_UNAVAILABLE,NO_SAFE_PRIMARY, orCONNECTION_ERRORin coordinator mode. It retries a failed read once, while it raises a failed write for reconciliation. Because a connection failure can also mean an outage, check the server's health before you retry.
A validation code such as INVALID_WRITER_WORKER, INVALID_MAX_BODY_BYTES, INVALID_DRIVER, or INVALID_ARGUMENT reports a mistake in the configuration or at the call site. Fix the mistake, because a retry fails in the same way.
UNAUTHORIZED and FORBIDDEN report a refused WebSocket upgrade. Because the server refuses that credential on every try, the client leaves the connection closed. Issue a fresh credential and build a new client to connect again.
HTTP status codes
| Status | Codes |
|---|---|
| 400 | INVALID_REQUEST, INVALID_JSON, EMPTY_BODY, INVALID_READ_LIMIT, INVALID_EXECUTION_TIMEOUT, QUERY_ERROR, TRANSACTION_ERROR, INVALID_DURABILITY, INVALID_SYNCHRONOUS, BATCH_VALIDATION_ERROR, MISSING_ARGUMENT, ARGUMENT_NOT_ALLOWED, UNSUPPORTED_SUBPROTOCOL, DEVICE_CLOCK_AHEAD |
| 401 | IDENTITY_REQUIRED |
| 403 | READ_ONLY, FORBIDDEN_SQL, HOOK_DENIED, SQL_NOT_ACCEPTED, BACKUP_RESTORE_NOT_ACCEPTED, DEVICE_SYNC_NOT_ACCEPTED, ENCRYPTION_CHANGE_NOT_ACCEPTED |
| 404 | DATABASE_NOT_FOUND, NOT_FOUND, UNKNOWN_QUERY |
| 409 | STALE_PRIMARY, PROTOCOL_VERSION_MISMATCH, MIGRATION_REQUIRED, SCHEMA_AHEAD, BACKUP_CHAIN_BROKEN, BACKUP_RESTORE_IN_PROGRESS, ENCRYPTION_CHANGE_IN_PROGRESS, ENCRYPTION_REQUIRED, REPLICATION_ACTIVE |
| 413 | PAYLOAD_TOO_LARGE |
| 422 | EXECUTION_TIMEOUT |
| 500 | INTERNAL_ERROR, HOOK_ERROR, WRITER_WORKER_TIMEOUT, INVALID_ENCRYPTION_KEY, ENCRYPTION_KEY_MISSING, ENCRYPTION_KEY_REJECTED, DATABASE_NOT_ENCRYPTED, ENCRYPTED_PAGE_CORRUPT, ENCRYPTION_CHANGE_ABORTED |
| 501 | BULK_LOAD_UNSUPPORTED, SYNC_UNSUPPORTED, BACKUP_UNSUPPORTED, ENCRYPTION_UNSUPPORTED, COLUMN_DETAILS_UNSUPPORTED, EXECUTION_TIMEOUT_UNSUPPORTED |
| 502 | BACKUP_DESTINATION_ERROR |
| 503 | DATABASE_CLOSED, SHUTDOWN, READ_CONCERN_ERROR, COORDINATOR_UNAVAILABLE, AUTHORITY_LOST, NO_SAFE_PRIMARY, NODE_NOT_IN_SYNC, NODE_DRAINING, UNSAFE_RECOVERY_REQUIRED, WRITE_OVERLOADED, ENCRYPTION_KEY_UNAVAILABLE |
The server answers a code outside the table with 500, while it answers a RequestDeniedError with the status that you give it. The server sends REGISTRY_MISMATCH only over WebSocket, when a live query subscribes, so that code has no HTTP status. The server answers WRITER_WORKER_TIMEOUT with 500, not 503, because the outcome of that write is indeterminate. Configure proxies to preserve that distinction and to make no automatic retries of writes.
WebSocket close codes
The server reports a refusal to an HTTP caller through the status code. A browser WebSocket can't read the status of a refused handshake, so the server reports those refusals to a socket in the close code.
| Close code | When |
|---|---|
1001 | The server shuts down once it sends the queued replies. |
1008 | The database in the URL is absent or closed. |
1009 | An incoming message exceeds maxBodyBytes. A refusal at the transport level can end the connection without a close frame. |
1011 | The server fails to open the database or to resolve its execution target, in which case it sends an error before it closes. |
4290 | The connection's outbound buffer exceeds maxWebSocketBackpressureBytes, or the client sends more than 256 messages, or more than four times maxBodyBytes, while the server opens the database. Clients that use device sync or subscription resumption recover from it. |
4401 | The authenticate hook refuses the upgrade with status 401, with a close reason that contains your code and message. |
4403 | The hook refuses the upgrade with status 403. |
4410 | The server removes the cursor of a connected device. Reconnect so that the resumption check can report whether the device needs a snapshot. |
The client reconnects after 4290 and resumes each subscription from its cursor. It treats 4401, 4403, and any code from 4000 to 4099 as a refusal and leaves that connection closed, because the server refuses that credential every time.