{"record":{"id":"e8cae982ca1a1736","repo":"sveltejs/kit","slug":"invalid-response-from-route-event-url-pathname","errorCode":null,"errorMessage":"Invalid response from route ${event.url.pathname}: handler should return a Response object","messagePattern":"Invalid response from route (.+?): handler should return a Response object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/kit/src/runtime/server/endpoint.js","lineNumber":54,"sourceCode":"\n\tif (state.prerendering && !state.prerendering.inside_reroute && !prerender) {\n\t\tif (state.depth > 0) {\n\t\t\t// if request came from a prerendered page, bail\n\t\t\tthrow new Error(`${event.route.id} is not prerenderable`);\n\t\t} else {\n\t\t\t// if request came direct from the crawler, signal that\n\t\t\t// this route cannot be prerendered, but don't bail\n\t\t\treturn new Response(undefined, { status: 204 });\n\t\t}\n\t}\n\n\ttry {\n\t\tconst response = await with_request_store({ event, state }, () =>\n\t\t\thandler(/** @type {import('@sveltejs/kit').RequestEvent<Record<string, any>>} */ (event))\n\t\t);\n\n\t\tif (!(response instanceof Response)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Invalid response from route ${event.url.pathname}: handler should return a Response object`\n\t\t\t);\n\t\t}\n\n\t\tif (state.prerendering && (!state.prerendering.inside_reroute || prerender)) {\n\t\t\t// The returned Response might have immutable Headers\n\t\t\t// so we should clone them before trying to mutate them.\n\t\t\t// We also need to clone the response body since it may be read twice during prerendering\n\t\t\tconst cloned = new Response(response.clone().body, {\n\t\t\t\tstatus: response.status,\n\t\t\t\tstatusText: response.statusText,\n\t\t\t\theaders: new Headers(response.headers)\n\t\t\t});\n\t\t\tcloned.headers.set('x-sveltekit-prerender', String(prerender));\n\n\t\t\tif (state.prerendering.inside_reroute && prerender) {\n\t\t\t\t// Without this, the route wouldn't be recorded as prerendered,\n\t\t\t\t// because there's nothing after reroute that would do that.","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/sveltejs/kit/blob/03f1687fe612ce3d2d9131139b5b188d9cf90c64/packages/kit/src/runtime/server/endpoint.js#L36-L72","documentation":"Runtime contract check in the endpoint renderer: after awaiting the route's handler, the returned value was not a Response instance. SvelteKit endpoint handlers must return a Response (e.g. via Response.json() or new Response(...)); returning plain objects, undefined, or other values fails this instanceof check. The message names the route path whose handler misbehaved.","triggerScenarios":"Thrown at packages/kit/src/runtime/server/endpoint.js:54 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Return a Response from the handler, e.g. `return Response.json({ ok: true })`","Wrap accidental plain-object returns with Response.json(...)","Check all code paths including early returns so none fall through to undefined"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"03f1687fe612ce3d2d9131139b5b188d9cf90c64","analyzedAt":"2026-09-02T02:01:50.504Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T06:17:21.866Z"}