Skip to content

Commit c7635c5

Browse files
committed
Update the serverFunctions.onError reference
1 parent 4c2c514 commit c7635c5

1 file changed

Lines changed: 17 additions & 6 deletions

File tree

src/routes/solid-start/v2/reference/config/solid-start.mdx

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,17 @@ solidStart({
139139

140140
Path to a module whose default export handles values thrown by server functions before SolidStart serializes them into a response.
141141

142-
The handler can report the original value and return a safer replacement for the client. Return `undefined` to preserve the original value. The module is bundled only into the server, so it can import server-only code.
142+
The export is called synchronously with the thrown value, and its return value is not awaited, so it cannot be an `async` function.
143+
144+
- Return `undefined` or `null` to preserve the original value.
145+
- Return a `Response` to have it handled as if the server function had thrown it.
146+
- Return any other value to send it in place of the original. It reaches the client serialized along with its own properties, so a replacement meant to be safe must not carry internal detail.
147+
148+
Control flow arrives the same way errors do: a [thrown `redirect`](/solid-start/v2/advanced/return-responses) reaches the export as a `Response`. Return those unchanged, or a handler that replaces everything it sees turns redirects into errors.
149+
150+
Only server function calls made over the network reach the export. A server function called during rendering runs in process and throws straight to its caller, and errors from API routes never reach it either.
151+
152+
The module is bundled only into the server, so it can import server-only code.
143153

144154
```tsx title="vite.config.ts"
145155
solidStart({
@@ -153,13 +163,14 @@ solidStart({
153163
import type { ServerFunctionErrorHandler } from "@solidjs/start/server";
154164

155165
const onServerFunctionError: ServerFunctionErrorHandler = (thrown) => {
156-
console.error(thrown);
157-
158-
if (thrown instanceof Error) {
159-
return new Error("The server function failed.");
166+
// `redirect` and friends throw a Response. Leave that control flow alone.
167+
if (thrown instanceof Response) {
168+
return thrown;
160169
}
161170

162-
return undefined;
171+
console.error(thrown);
172+
173+
return new Error("The server function failed.");
163174
};
164175

165176
export default onServerFunctionError;

0 commit comments

Comments
 (0)