When an error occurs, an object of type CRXError is thrown. It includes a code property that indicates the type of error. the value of code is defined in the API_ERRORS object. You can handle errors using a try-catch block as follows:
import { Client, CRXError, API_ERRORS } from "@crxbase/client";

const client = new Client("your_project_id");

try {
	const user = await client.getUser();
} catch (error) {
	if (error instanceof CRXError) {
		if (error.code === API_ERRORS.UNAUTHORIZED) {
			console.log("User is not authorized. Please log in.");
		}
	} else {
		console.error("An unexpected error occurred:", error);
	}
}

Errors

const API_ERRORS = {
	CREDITS_NOT_ENOUGH: "credits_not_enough",
	CREDITS_NOT_FOUND: "credits_not_found",
	PLAN_NOT_FOUND: "plan_not_found",
	UNAUTHORIZED: "unauthorized",
	UNKNOWN: "unknown",
};
KeyValueDescription
CREDITS_NOT_ENOUGHcredits_not_enoughNot enough credits available.
CREDITS_NOT_FOUNDcredits_not_foundNo credits found for user.
PLAN_NOT_FOUNDplan_not_foundNo plan found for user.
UNAUTHORIZEDunauthorizedUser is not authorized.
UNKNOWNunknownAn unknown error occurred.