{
  "id": "e05a7cee7291ecbc1e1b739b",
  "source": "solid:signals",
  "type": "github-document",
  "title": "return-responses",
  "content": "---\ntitle: Returning responses\nuse_cases: \u003e-\n  server function responses, error handling, response types, api responses,\n  typescript typing\ntags:\n  - responses\n  - server\n  - functions\n  - typescript\n  - errors\n  - api\nversion: '1.0'\ndescription: \u003e-\n  Return typed Response objects from server functions. Handle redirects,\n  reloads, and JSON responses with proper TypeScript support.\n---\n\nIn SolidStart, it is possible to return a Response object from a server function.\n[`solid-router`](/solid-router) knows how to handle certain responses with its [`query`](/solid-router/reference/data-apis/query) and [`action`](/solid-router/reference/data-apis/action) APIs.\nFor TypeScript, when returning a response using `solid-router`'s `redirect`, `reload`, or `json` helpers, they will not impact the return value of the server function.\n\nWhile we suggest depending on the type of the function to handle errors differently, you can always return or throw a response.\n\n## Examples\n\nIn the following example, the `hello` function will return a value of type `Promise\u003c{ hello: string }\u003e`:\n\n```tsx\nimport { json } from \"@solidjs/router\";\nimport { GET } from \"@solidjs/start\";\n\nconst hello = GET(async (name: string) =\u003e {\n\t\"use server\";\n\treturn json(\n\t\t{ hello: new Promise\u003cstring\u003e((r) =\u003e setTimeout(() =\u003e r(name), 1000)) },\n\t\t{ headers: { \"cache-control\": \"max-age=60\" } }\n\t);\n});\n```\n\nHowever, in this example, since `redirect` and `reload` return `never` as their type, `getUser` can only return a value of type `Promise\u003cUser\u003e`:\n\n```tsx { 4, 10, 14}\nexport async function getUser() {\n\t\"use server\";\n\n\tconst session = await getSession();\n\tconst userId = session.data.userId;\n\tif (userId === undefined) return redirect(\"/login\");\n\n\ttry {\n\t\tconst user: User = await db.user.findUnique({ where: { id: userId } });\n\t\t// throwing can be awkward.\n\t\tif (!user) return redirect(\"/login\");\n\t\treturn user;\n\t} catch {\n\t\t// do stuff\n\t\tthrow redirect(\"/login\");\n\t}\n}\n```",
  "url": "https://github.com/solidjs/solid-docs/blob/HEAD/src/routes/solid-start/advanced/return-responses.mdx",
  "metadata": {
    "path": "src/routes/solid-start/advanced/return-responses.mdx",
    "repo": "solidjs/solid-docs",
    "repo_url": "https://github.com/solidjs/solid-docs.git",
    "size": 1953,
    "source_type": "github"
  },
  "hash": "792dc9c455106e563fed04789df8ac99d81382249716b715ff1306e5dedfb1a5",
  "timestamp": "2026-02-23T11:43:00.193644172+01:00"
}