Skip to content

Commit 151e04d

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

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,13 @@ solidStart({
137137

138138
- **Type:** `string`
139139

140-
Path to a module whose default export handles values thrown by server functions before SolidStart serializes them into a response.
140+
Path to a module whose default export handles values thrown by server functions before SolidStart serializes them into a response. Only calls arriving over the network reach it. The module is bundled only into the server, so it can import server-only code.
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 runs synchronously, and its return value is not awaited, so an `async` export sends the promise rather than what it resolves to.
143+
144+
- Return `undefined` or `null` to preserve the original value.
145+
- Return a `Response` unchanged to pass it through, which keeps a thrown `redirect` working. See [Return Responses](/solid-start/v2/advanced/return-responses).
146+
- Return any other value to send it in place of the original, serialized to the client along with its own properties.
143147

144148
```tsx title="vite.config.ts"
145149
solidStart({
@@ -149,17 +153,21 @@ solidStart({
149153
});
150154
```
151155

156+
The module it names, `src/server-function-error.ts`:
157+
152158
```ts title="src/server-function-error.ts"
153159
import type { ServerFunctionErrorHandler } from "@solidjs/start/server";
160+
import { captureException } from "./your-monitoring-client";
154161

155162
const onServerFunctionError: ServerFunctionErrorHandler = (thrown) => {
156-
console.error(thrown);
157-
158-
if (thrown instanceof Error) {
159-
return new Error("The server function failed.");
163+
// redirect() throws a Response, so returning it preserves that control flow.
164+
if (thrown instanceof Response) {
165+
return thrown;
160166
}
161167

162-
return undefined;
168+
captureException(thrown); // or console.error, or any reporter
169+
170+
return new Error("The server function failed.");
163171
};
164172

165173
export default onServerFunctionError;

0 commit comments

Comments
 (0)