KontextError base class
Errors thrown by the SDK’s core operations areKontextError instances or subclasses. Each error carries structured metadata for programmatic handling.
Properties
| Property | Type | Description |
|---|---|---|
code | string | Machine-readable error code, typically prefixed with kontext_. Upstream server codes may differ. |
statusCode | number? | HTTP status code when applicable |
docsUrl | string | Link to the error documentation page |
requestId | string? | Server request ID for debugging |
meta | Record<string, unknown> | Contextual metadata (integration IDs, URLs, etc.) |
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.
| Code | Status | Meaning |
|---|---|---|
kontext_authorization_required | 401 | User needs to authenticate. Start the OAuth flow. |
kontext_integration_connection_required | 403 | Integration needs user connection. Check connectUrl in meta or on the error instance. This can be OAuth or API key setup. |
kontext_oauth_token_exchange_failed | 400 | OAuth token exchange failed. Inspect errorCode and meta. |
kontext_oauth_code_verifier_missing | 400 | PKCE verifier is missing (usually callback state lost). |
kontext_config_missing_client_id | — | SDK config is missing clientId. |
kontext_config_missing_redirect_uri | — | SDK config is missing redirectUri. |
kontext_config_missing_auth_handler | — | SDK config is missing onAuthRequired. |
kontext_network_error | — | Connection or network failure. DNS resolution, timeouts, or refused connections. |
kontext_mcp_parse_error | — | The MCP peer returned invalid JSON-RPC payloads. |
kontext_mcp_invalid_request | — | The MCP request was structurally invalid. |
kontext_mcp_invalid_params | — | Tool arguments or MCP call params were invalid. |
kontext_mcp_method_not_found | — | The MCP peer does not support the requested method. |
kontext_mcp_internal_error | 500 | The MCP peer failed while handling the request. |
kontext_mcp_session_expired | 401 | The MCP session timed out or the transport considers it expired. |
kontext_mcp_session_error | — | The MCP transport closed unexpectedly. |
kontext_mcp_error | — | Fallback for other negative MCP JSON-RPC codes. |
kontext_validation_error | 400 | Request validation failed. Check validationErrors. |
kontext_policy_denied | 403 | Action denied by policy evaluation. |
kontext_not_found | 404 | Requested resource does not exist. |
kontext_rate_limited | 429 | Rate limit exceeded. Check retryAfter when available. |
kontext_server_error | varies | Server or upstream failure. Commonly 5xx, but the client translation layer may emit this for other HTTP status codes. Retry with backoff. |
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.