Skip to content

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
}
}
ErrorTypesMeaning
BadRequestThe call itself is wrong, e.g. an invalid filter or too large a file
UnspecifiedSomething else failed, e.g. the server can’t be reached
NoPermissionThe user may not do this
ReservedCollectionNameCollection names starting with _ are reserved
CollectionDoesNotExistNo such collection
DatabaseDoesNotExistThe owner has no database in this app yet
AlreadyExistsThe ID or name is taken
UserDoesNotExistNo such user
OrgDoesNotExistNo such org
TeamDoesNotExistNo such team
FileDoesNotExistNo such file
NoSpaceThe owner’s storage is full
RequestLimitToo many requests
LimitReachedA limit of the plan is reached, e.g. the number of products
ProfileIncompleteThe 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";