/** * Where an error passed to `handleError` came from. Added in SvelteKit 3; `undefined` on * SvelteKit 1.x and 2.x. * * - `app`: thrown with the `error(...)` helper * - `framework`: generated by SvelteKit itself (404s, 405s, 413s, ...) * - `validation`: invalid remote function arguments (server only) * - `unknown`: thrown by user code, or code it calls * * @see https://svelte.dev/docs/kit/hooks#handleError */ export type CaughtErrorKind = 'app' | 'framework' | 'validation' | 'unknown'; /** * The `handleError` input as of SvelteKit 3, where errors are discriminated by `kind` and the * status lives on the error instead of the input. */ export type CaughtErrorInput = { kind: CaughtErrorKind; error: unknown; /** Only present for `kind: 'validation'` */ issues?: unknown[]; }; /** * The `handleError` input on SvelteKit 1.x and 2.x, which had no `kind` and carried the status and * message on the input itself. * * SvelteKit 3 keeps both alive in dev builds as deprecated getters that log a warning when read. * Modelling the two shapes as a discriminated union is what stops us reading them on a SvelteKit 3 * input: as far as the type system is concerned, `status` doesn't exist there. */ export type LegacyCaughtErrorInput = { kind?: undefined; error: unknown; status?: number; message?: string; }; /** * The input of a SvelteKit `handleError` hook, covering SvelteKit 1.x, 2.x and 3. * * We declare this structurally instead of importing SvelteKit's `HandleServerError`/ * `HandleClientError`, because those types moved from `@sveltejs/kit` to `@sveltejs/kit/hooks` * in SvelteKit 3 and neither import path type-checks against both majors. */ export type SentryHandleErrorInput = CaughtErrorInput | LegacyCaughtErrorInput; /** The `handleError` input on the server, where we also read from the request event. */ export type SentryHandleServerErrorInput = SentryHandleErrorInput & { event: { route?: { id?: string | null; }; platform?: unknown; }; }; /** The `handleError` input on the client. */ export type SentryHandleClientErrorInput = SentryHandleErrorInput & { event: unknown; }; /** * Constrains the user-provided `handleError` hook without depending on SvelteKit's own types. * `never` as the parameter type accepts any single-argument function (parameters are * contravariant), so a SvelteKit 1.x, 2.x or 3 hook all satisfy it. */ export type AnyErrorHandler = (input: never) => unknown; /** * Reads the HTTP status off an error. In SvelteKit 3, `app`, `framework` and `validation` errors * all carry their status here. */ export declare function getErrorStatus(error: unknown): number | undefined; /** * Whether an error passed to `handleError` should be sent to Sentry. * * @param isExpectedLegacyError checks whether a SvelteKit 1.x/2.x error is an expected one. Those * versions have no `kind`, and what counts as expected differs between server and client. */ export declare function shouldCaptureError(input: SentryHandleErrorInput, isExpectedLegacyError: () => boolean): boolean; //# sourceMappingURL=handleErrorTypes.d.ts.map