WaitKitWaitKit
JavaScript SDK

SDK Errors

Handle WaitKitError thrown by the JavaScript SDK. Learn try-catch patterns, error status codes (400, 401, 404, 409, 429), and how to parse validation issues from API responses.

SDK methods throw WaitKitError when an API request fails. The error includes the HTTP status code and any validation issues.

WaitKitError

class WaitKitError extends Error {
  name: "WaitKitError";
  statusCode?: number;
  issues?: Array<{ path: string; message: string }>;
}
FieldTypeDescription
messagestringHuman-readable error message
statusCodenumber | undefinedHTTP status code from the API response
issuesArray<{ path: string; message: string }>Validation error details

Handling errors

Check the error type before accessing SDK-specific fields:

import { WaitKit, WaitKitError } from "waitkit";

try {
  await wk.subscribers.create({ email: "invalid" });
} catch (err) {
  if (err instanceof WaitKitError) {
    console.error(`Error ${err.statusCode}: ${err.message}`);
    if (err.issues) {
      for (const issue of err.issues) {
        console.error(`  ${issue.path}: ${issue.message}`);
      }
    }
  } else {
    // Network error or unexpected issue
    console.error("Unexpected error:", err);
  }
}

Common error codes

CodeErrorCause
400Bad RequestMissing or invalid email field
401UnauthorizedMissing, invalid, or revoked API key
404Not FoundProject slug does not exist
409ConflictEmail already registered for this project
429Too Many RequestsRate limit exceeded
500Internal ErrorServer error (contact support if persistent)

For detailed troubleshooting of each scenario, see the Troubleshooting guide.

On this page