sveltejs/kit · warning · HttpError
Error: ${status}
Error message
Error: ${status} What it means
This is not a thrown JS error but the default message of the HttpError that error(status) creates when no message argument is supplied: `Error: ${status}` (e.g. 'Error: 404'). SvelteKit renders it through its error-handling flow (error page, +error.svelte, or serialized error response). It appears when a load function or action calls error(status) without a human-readable message.
Source
Thrown at packages/kit/src/exports/index.js:96
* @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.
* @throws {Error} If the provided status is invalid (not between 400 and 599).
*/
export function error(status, message, properties) {
if ((!BROWSER || DEV) && (isNaN(status) || status < 400 || status > 599)) {
throw new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);
}
if (message !== undefined && typeof message !== 'string') {
if (DEV) {
console.warn(
'Passing an `App.Error` body as the second argument is deprecated — pass the `message` as the second argument, and any additional properties as the third'
);
}
({ message, ...properties } = message);
}
throw new HttpError({ ...properties, status, message: message ?? `Error: ${status}` });
}
/**
* Checks whether this is an error thrown by {@link error}.
* @template {number} T
* @param {unknown} e
* @param {T} [status] The status to filter for.
* @return {e is (import('./public.js').HttpError & { status: T extends undefined ? never : T })}
*/
export function isHttpError(e, status) {
if (!(e instanceof HttpError)) return false;
return !status || e.status === status;
}
/**
* Redirect a request. When called during request handling, SvelteKit will return a redirect response.
* Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.
*View on GitHub (pinned to 03f1687fe6)
Solutions
- Pass a descriptive message: error(404, 'Post not found') — this becomes page.error.message.
- Handle the status in +error.svelte and map codes to friendly text instead of showing e.message raw.
- For a fully custom shape, throw error() with properties (third argument) or use fail() in form actions for validation feedback.
Example fix
// before
if (!post) error(404);
// after
if (!post) error(404, `Post '${id}' was not found`); Defensive patterns
Strategy: fallback
Validate before calling
if (arguments.length < 2) console.warn('error() called without a message — the UI will show "Error: ' + status + '"'); Type guard
null
Try / catch
try {
error(404);
} catch (e) {
if (isHttpError(e) && !e.body.message.startsWith('Error:')) throw e;
error(404, 'Resource not found');
} Prevention
- Treat the second argument of error() as required in your codebase via lint rules or code review.
- Render friendly messages in +error.svelte based on page.error.status rather than echoing raw message.
- Provide project-specific messages like error(404, `Post '${id}' not found`).
When it happens
Trigger: Calling error(404) or error(403) with no second (message) argument, or passing undefined — resulting in page.error.message === 'Error: 404' in the UI or response.
Common situations: Quick-guard clauses like if (!data) error(404); API endpoints surfacing terse messages to clients; users seeing 'Error: 404' in +error.svelte because no custom message was provided.
Related errors
- HTTP error status codes must be between 400 and 599 — ${stat
- Invalid status code
- Cannot `return error(...)` — use `error(...)` or `return fai
- exports is not available in dev mode
- The `generateManifest` adapter API has been removed — use `g
AI-assisted analysis of sveltejs/kit@03f1687fe6 (2026-09-02).
Data as JSON: /api/errors/61041f3595c85c3e.
Report an issue: GitHub.