Handle Errors
SDK calls that fail throw a BazaarError. Its type says what happened, its message says it for a developer.
import { BazaarError, ErrorTypes } from "@bzr/bazaar";
try { await bzr.files.upload(file);} catch (err) { if (err instanceof BazaarError && err.type === ErrorTypes.NoSpace) { // Tell the user their storage is full }}ErrorTypes | Meaning |
|---|---|
BadRequest | The call itself is wrong, e.g. an invalid filter or too large a file |
Unspecified | Something else failed, e.g. the server can’t be reached |
NoPermission | The user may not do this |
ReservedCollectionName | Collection names starting with _ are reserved |
CollectionDoesNotExist | No such collection |
DatabaseDoesNotExist | The owner has no database in this app yet |
AlreadyExists | The ID or name is taken |
UserDoesNotExist | No such user |
OrgDoesNotExist | No such org |
TeamDoesNotExist | No such team |
FileDoesNotExist | No such file |
NoSpace | The owner’s storage is full |
RequestLimit | Too many requests |
LimitReached | A limit of the plan is reached, e.g. the number of products |
ProfileIncomplete | The user hasn’t finished signing up |
For the most common ones there are helpers:
import { isNoPermissionError, isUserDoesNotExistError, isNoAppUserError, // DatabaseDoesNotExist: the user hasn't used your app yet} from "@bzr/bazaar";