import type { SENTRY_ERROR_EXTRA_KEYS, SentryOperationErrorCode } from "./error-codes.gen.ts"; /** * The generated SDK's non-throwing result shape. * * Defined locally so the hand-written helpers never import generated code. */ export type SdkResult = { data: TData; error?: never; request: Request; response: Response; } | { data?: never; error: TError; request: Request; response: Response | undefined; }; type ErrorStatus = Extract; /** An API error whose status and body were declared by the operation. */ export type DocumentedSentryApiError = { [TStatus in ErrorStatus]: SentryApiError; }[ErrorStatus]; /** An API error returned under a status absent from the operation's schema. */ export type UndocumentedSentryApiError = SentryApiError; /** * @deprecated Non-HTTP failures propagate unchanged. Typed-error helpers only * return HTTP failures and no longer produce this legacy wrapper. */ export type SentryApiTransportError = SentryApiError; export type SentryApiResultError = DocumentedSentryApiError | UndocumentedSentryApiError; export type NarrowedResult = { ok: true; data: TData; response: Response; } | { ok: false; error: SentryApiResultError; }; /** * Codes the backend sends, from the spec: those of its `SentryAPIException` * subclasses, and the other `code` values operations document in their error * responses, such as Seer's `seer_out_of_credits`. */ export type KnownSentryErrorCode = keyof typeof SENTRY_ERROR_EXTRA_KEYS | SentryOperationErrorCode; /** The string fields each `SentryAPIException` code's `extra` can carry. */ export type SentryErrorExtra = { [TKey in (typeof SENTRY_ERROR_EXTRA_KEYS)[TCode][number]]?: string; }; /** A known code, or another code the server sends. */ export type SentryErrorCode = KnownSentryErrorCode | (string & {}); /** The `detail` of a `{"detail": {"code", "message", "extra"}}` error body. */ export type SentryErrorDetail = { code: SentryErrorCode; message: string; extra: Record; }; /** Read a `SentryAPIException` body; undefined for any other body. */ export declare function readSentryErrorDetail(body: unknown): SentryErrorDetail | undefined; /** An API failure with its parsed body and raw response. */ export declare class SentryApiError extends Error { readonly status: TStatus; readonly body: TBody; readonly response: Response | undefined; readonly documented: TDocumented; readonly request?: Request; /** Original response text, captured during the same read as the parsed body. */ readonly rawBody?: string; /** * The `code` of a `{"detail": {"code", "message", "extra"}}` body, which the * backend's `SentryAPIException` sends, or else a top-level string `code`, * such as Seer's `{"detail", "code", "denialReason"}` 402. */ readonly code?: SentryErrorCode; /** That body's `message`, or a top-level body's string `detail`. `message` stays this error's own. */ readonly detailMessage?: string; /** That body's `extra`, such as `loginUrl` for `sso-required`; empty for a top-level `code`. */ readonly extra?: Record; constructor(status: TStatus, body: TBody, response: Response | undefined, documented: TDocumented, message?: string, options?: ErrorOptions & { request?: Request; rawBody?: string; }); } /** Whether `error` is a `SentryApiError` whose body has the given `code`. */ export declare function isSentryErrorCode(error: unknown, code: TCode): error is SentryApiError & { code: TCode; detailMessage: string; extra: Record; }; /** A `SentryApiError`'s request and response fields; see `getSentryApiErrorDetails`. */ export type SentryApiErrorDetails = { /** The request method, or `GET` when the error has no request. */ method: string; /** The request URL's path, without origin or query, when there is a request. */ path?: string; status?: number; statusText?: string; /** The parsed response body, when it was JSON. */ responseJSON?: unknown; /** The response text, when the transport read it. */ responseText?: string; /** `METHOD /path status`, with `n/a` for a missing status, such as `GET /api/0/organizations/ 404`. */ summary: string; }; /** * Collect what an application's own error class usually carries from a * `SentryApiError`, such as in an error interceptor that maps SDK errors. * Pass the interceptor's `request` for errors that do not carry one. * * @example * ```ts * sentry.client.interceptors.error.use((error, _response, request) => * error instanceof SentryApiError * ? new AppRequestError(getSentryApiErrorDetails(error, request), { cause: error }) * : error, * ); * ``` */ export declare function getSentryApiErrorDetails(error: SentryApiError, request?: Request | undefined): SentryApiErrorDetails; /** * Convert an SDK result to a status-discriminated HTTP result. * * Prefer the generated `narrowError_` wrappers. They supply the * operation's complete error map and documented statuses automatically. * Base SentryApiError instances for this response are reclassified, including * ones supplied by an interceptor. Other errors (including subclasses) are * thrown unchanged. Status narrowing does not validate the response body. */ export declare const narrowError: (result: SdkResult, documentedStatuses: ReadonlyArray>) => NarrowedResult; /** * Call an SDK operation and narrow its default HTTP errors by status. * Generated operation wrappers use this helper. Errors outside narrowError's * HTTP contract reject without being relabeled or wrapped. */ export declare const callWithTypedErrors: (call: () => Promise>, documentedStatuses: ReadonlyArray>) => Promise>; export {};