Skip to article

SearchError

Stable normalized failure codes with a trace and sanitized diagnostic fields.

On this page

Handle by code

errors.ts · fixture
import { createSearch, SearchError } from '@belweave/search-sdk';
import { createMockProvider } from '@belweave/search-sdk/testing';

const client = createSearch({ provider: createMockProvider({
  outcomes: [{ type: 'error', code: 'rate_limit', retryAfterMs: 2_000 }],
}) });

try {
  await client.web.search({ query: 'SQLite concurrency' });
} catch (error) {
  if (!(error instanceof SearchError)) throw error;
  console.log(error.code, error.status, error.retryAfterMs);
  console.log(error.attempts); // Fixed codes and timing, no raw error bodies
}

Error codes

CodeFallback / meaning
rate_limitYes — HTTP 429.
networkYes — rejected transport, including blocked redirects.
unavailableYes — HTTP 408 or 5xx.
attempt_timeoutYes — attempt budget elapsed while total time remains.
timeoutNo — total call budget elapsed.
abortedNo — caller cancelled.
authNo — account/auth failures, including HTTP 401/402/403.
invalid_requestNo — request or call options are invalid.
unsupported_optionNo — a configured provider cannot satisfy a required option.
configurationNo — invalid setup or exhausted fixture outcomes.
invalid_responseNo — malformed consumed response data.
provider_errorNo — other rejected requests or custom exceptions.

Diagnostic fields

Read code, attempts, optional status, and optional retryAfterMs. Error messages are fixed by code. Raw provider bodies, transport messages, credentials, and caller abort reasons are excluded. Avoid attaching your own secret-bearing request objects to errors.