{"record":{"id":"2d49fbb49a8a8373","repo":"sveltejs/kit","slug":"passing-an-app-error-body-as-the-second-argument","errorCode":null,"errorMessage":"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","messagePattern":"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","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/kit/src/exports/index.js","lineNumber":88,"sourceCode":" * Throws an error with a HTTP status code and an optional message.\n * When called during request handling, this will cause SvelteKit to\n * return an error response; the error will be passed to `handleError` as an _expected_ error.\n * Make sure you're not catching the thrown error, which would prevent SvelteKit from handling it.\n * @param {any} status The [HTTP status code](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status#client_error_responses). Must be in the range 400-599.\n * @param {any} [message] A string, or (deprecated) a partial App.Error object\n * @param {any} [properties] Additional properties of the App.Error type when passing a string message.\n * @return {never}\n * @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) {","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/exports/index.js#L70-L106","documentation":"`error(status, body)` in $app/utils warns in dev when the second argument is an object rather than a string. The object's `message` property is used and the rest become `properties`, but this overload is deprecated in favor of `error(status, message, properties)`.","triggerScenarios":"Calling `throw error(404, { message: 'Not found', code: 'X' })` in a load function or `+server.js` during dev (DEV only).","commonSituations":"Code written against older SvelteKit APIs before the three-argument signature existed; copied legacy error helpers.","solutions":["Split the call: pass the message string second and the remaining properties as a third argument","Search the codebase for `error(` calls whose second argument is an object literal","Update tests that assert on the deprecated overload"],"exampleFix":"// before\nerror(404, { message: 'Not found', code: 'MISSING' });\n// after\nerror(404, 'Not found', { code: 'MISSING' });","handlingStrategy":"type-guard","validationCode":"// helper to migrate calls safely\nfunction kitError(status, message, properties) {\n  if (typeof message !== 'string') {\n    const { message: msg, ...props } = message;\n    return kitError(status, msg, props);\n  }\n  return { status, message, properties };\n}","typeGuard":"const isAppErrorBody = (m) => typeof m === 'object' && m !== null && typeof m.message === 'string';","tryCatchPattern":"// load/+server.js\nimport { error } from '@sveltejs/kit';\ntry {\n  if (!user) throw error(404, 'Not found', { code: 'MISSING' });\n} catch (e) {\n  if (isHttpError(e)) return json({ code: e.body.code }, { status: e.status });\n  throw e;\n}","preventionTips":["Wrap error() calls in project helpers enforcing the (status, message, properties) signature","ESLint rule banning object literals as error()'s second argument","Keep error helpers updated with the current @sveltejs/kit types"],"tags":["deprecation","error-handling","api-migration"],"backgroundTag":"deprecated-error-signature","analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}