Core
Guides v2.x
2

Errors #

Available since 2.61.0

A driver throws Kuzzle's storage errors, so that a client gets the same error whatever the engine. kuzzle exports them as storageError, which builds the services.storage.* errors listed in the error codes page:

import { storageError } from "kuzzle";

// services.storage.not_found: Document "<id>" not found in "<index>":"<collection>".
throw storageError.get("not_found", id, index, collection);

storageError.get(id, ...placeholders) fills the error's message with the placeholders, in the order its code states; storageError.reject(...) returns the same error as a rejected promise.

Translate the engine's own errors into the closest storage error:

Engine situationError
Document not foundnot_found
Document already existsdocument_already_exists
Index or collection not foundunknown_index, unknown_collection
Version conflicttoo_many_changes
Engine unreachablenot_connected
Unsupported engine versionversion_mismatch
Anything elseunexpected_error, with the engine's message

The other error classes (BadRequestError, NotFoundError, KuzzleError...) are exported by kuzzle too. Import them from the kuzzle peer dependency, never from a copy of Kuzzle of your own: Kuzzle recognizes its errors by class, and an error from another copy reaches clients as an internal error.

A request needing a capability your driver does not declare never reaches it: Kuzzle rejects it first, with services.storage_driver.unsupported_capability.