Errors
One error class with the API's stable code, request id and validation details.
Every error is an EmitKitError. Switch on code, never on the message:
import { EmitKitError } from "@emitkit/js";
try {
await emitkit.events.create({ channelName: "deploys", title: "Deployed" });
} catch (error) {
if (error instanceof EmitKitError) {
if (error.code === "validation_error") {
console.error(error.details); // [{ path: ["title"], message: "…" }]
} else if (error.code === "rate_limited") {
console.error(`Try again in ${error.retryAfter}s`);
}
console.error(error.status, error.requestId);
}
throw error;
}
code is one of the API’s error codes
(validation_error, unauthorized, forbidden, not_found, …) or the
SDK’s own: network_error, timeout, missing_api_key and
invalid_signature (from verifyCallback).
Record the request id when asking for support. Never record the API key or
the complete Authorization header.