KontextError base class
Errors thrown by the SDK’s core operations areKontextError instances or subclasses. Each error carries structured metadata for programmatic handling.
Properties
Type guard
UseisKontextError() to check errors without instanceof. This works across package versions and bundler deduplication.
Error codes
The SDK emits manykontext_* codes. The table below lists common codes you should handle explicitly.
Specific error classes
Import error classes from@kontext-dev/js-sdk/errors:
AuthorizationRequiredError
Thrown when no valid credentials are available. Redirect the user to sign in.IntegrationConnectionRequiredError
Thrown when a user has not connected a required integration. TheconnectUrl property may contain the URL to complete integration setup (OAuth or API key flow).
kontext.require("github", { userId }), connectUrl is usually undefined. That path does not have a bearer token available to create a connect session on the user’s behalf.
OAuthError
Thrown when an OAuth flow fails. Covers state validation errors, token exchange failures, and provider-side rejections.ConfigError
Thrown at initialization when the SDK is misconfigured. These are deterministic errors you can catch during startup.NetworkError
Thrown on connection failures — DNS resolution errors, timeouts, refused connections.HttpError
Thrown when the server returns an HTTP error. Includes extra fields for specific status codes.Detection helpers
Two utility functions for common checks:Error translation helper
UsetranslateError() when you are working with low-level MCP client calls or third-party wrappers and want the same normalized KontextError surface that the higher-level SDK uses internally.
translateError() maps MCP JSON-RPC negative codes, Streamable HTTP errors, 401s, and browser/network failures into stable kontext_* codes.