{"record":{"id":"61041f3595c85c3e","repo":"sveltejs/kit","slug":"error-status","errorCode":null,"errorMessage":"Error: ${status}","messagePattern":"Error: (.+?)","errorType":"http","errorClass":"HttpError","httpStatus":null,"severity":"warning","filePath":"packages/kit/src/exports/index.js","lineNumber":96,"sourceCode":" * @throws {import('./public.js').HttpError} This error instructs SvelteKit to initiate HTTP error handling.\n * @throws {Error} If the provided status is invalid (not between 400 and 599).\n */\nexport function error(status, message, properties) {\n\tif ((!BROWSER || DEV) && (isNaN(status) || status < 400 || status > 599)) {\n\t\tthrow new Error(`HTTP error status codes must be between 400 and 599 — ${status} is invalid`);\n\t}\n\n\tif (message !== undefined && typeof message !== 'string') {\n\t\tif (DEV) {\n\t\t\tconsole.warn(\n\t\t\t\t'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'\n\t\t\t);\n\t\t}\n\n\t\t({ message, ...properties } = message);\n\t}\n\n\tthrow new HttpError({ ...properties, status, message: message ?? `Error: ${status}` });\n}\n\n/**\n * Checks whether this is an error thrown by {@link error}.\n * @template {number} T\n * @param {unknown} e\n * @param {T} [status] The status to filter for.\n * @return {e is (import('./public.js').HttpError & { status: T extends undefined ? never : T })}\n */\nexport function isHttpError(e, status) {\n\tif (!(e instanceof HttpError)) return false;\n\treturn !status || e.status === status;\n}\n\n/**\n * Redirect a request. When called during request handling, SvelteKit will return a redirect response.\n * Make sure you're not catching the thrown redirect, which would prevent SvelteKit from handling it.\n *","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/exports/index.js#L78-L114","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nif (!post) error(404);\n// after\nif (!post) error(404, `Post '${id}' was not found`);","handlingStrategy":"fallback","validationCode":"if (arguments.length < 2) console.warn('error() called without a message — the UI will show \"Error: ' + status + '\"');","typeGuard":"null","tryCatchPattern":"try {\n  error(404);\n} catch (e) {\n  if (isHttpError(e) && !e.body.message.startsWith('Error:')) throw e;\n  error(404, 'Resource not found');\n}","preventionTips":["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`)."],"tags":["sveltekit","http-status","error-handling","user-experience"],"backgroundTag":"generic-error-page-message","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}