Skip to main content

KontextError base class

Errors thrown by the SDK’s core operations are KontextError instances or subclasses. Each error carries structured metadata for programmatic handling.

Properties

Type guard

Use isKontextError() to check errors without instanceof. This works across package versions and bundler deduplication.

Error codes

The SDK emits many kontext_* 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. The connectUrl property may contain the URL to complete integration setup (OAuth or API key flow).
If you called 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:
These helpers primarily use structural checks (status codes, system error codes) with fallback string checks for compatibility with the MCP SDK, so they work with errors from any source — the SDK, fetch wrappers, or the MCP protocol.

Error translation helper

Use translateError() 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.