Skip to content

Commit 34879bd

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

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

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

Lines changed: 14 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.
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({
@@ -150,16 +154,19 @@ solidStart({
150154
```
151155

152156
```ts title="src/server-function-error.ts"
157+
// src/server-function-error.ts
153158
import type { ServerFunctionErrorHandler } from "@solidjs/start/server";
159+
import * as Sentry from "@sentry/node";
154160

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

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

165172
export default onServerFunctionError;

0 commit comments

Comments
 (0)