@solidjs/start 2.0.0-rc.6 → 2.0.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/dist/config/index.d.ts +33 -11
- package/dist/fns/error-handler.d.ts +33 -2
- package/dist/fns/error-handler.js +8 -3
- package/dist/fns/handler.js +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# @solidjs/start
|
|
2
2
|
|
|
3
|
+
## 2.0.0-rc.8
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3573985: Await asynchronous `serverFunctions.onError` handlers before serializing server function errors.
|
|
8
|
+
Preserve the original error if the handler throws or rejects.
|
|
9
|
+
|
|
10
|
+
## 2.0.0-rc.7
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- 87d73e1: chore: bump seroval to v1.6.0
|
|
15
|
+
|
|
3
16
|
## 2.0.0-rc.6
|
|
4
17
|
|
|
5
18
|
### Minor Changes
|
package/dist/config/index.d.ts
CHANGED
|
@@ -115,22 +115,44 @@ export interface SolidStartOptions {
|
|
|
115
115
|
*/
|
|
116
116
|
env?: EnvPluginOptions;
|
|
117
117
|
/**
|
|
118
|
-
* Options
|
|
119
|
-
* (inclusion / exclusion filters
|
|
118
|
+
* Options for server functions: which files the `"use server"` transform
|
|
119
|
+
* processes (inclusion / exclusion filters), and what happens when a server
|
|
120
|
+
* function throws.
|
|
120
121
|
*/
|
|
121
122
|
serverFunctions?: Pick<ServerFunctionsOptions, "filter"> & {
|
|
122
123
|
/**
|
|
123
|
-
* Path to a module whose default export
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
124
|
+
* Path to a module whose default export handles whatever a server function
|
|
125
|
+
* throws, before it reaches the client. Use it to report failures to a
|
|
126
|
+
* monitoring service, or to replace an error carrying internal detail with
|
|
127
|
+
* one that is safe to send.
|
|
127
128
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
129
|
+
* Only server function calls made over the network run through it. A
|
|
130
|
+
* server function called during rendering runs in process and throws
|
|
131
|
+
* straight to its caller, and errors from API routes never reach it
|
|
132
|
+
* either.
|
|
131
133
|
*
|
|
132
|
-
* The
|
|
133
|
-
*
|
|
134
|
+
* The handler may be asynchronous. SolidStart awaits its return value
|
|
135
|
+
* before serializing the response, allowing a monitoring service to flush
|
|
136
|
+
* first. The resolved value decides what the client sees:
|
|
137
|
+
*
|
|
138
|
+
* - `undefined` (or `null`) sends what was thrown, unchanged.
|
|
139
|
+
* - A `Response` is passed through unchanged, which keeps a thrown
|
|
140
|
+
* `redirect()` working.
|
|
141
|
+
* - Any other value is sent in place of what was thrown, and the client
|
|
142
|
+
* call rejects with it.
|
|
143
|
+
* - If the handler throws or rejects, what the server function threw is
|
|
144
|
+
* sent unchanged.
|
|
145
|
+
*
|
|
146
|
+
* Control flow reaches the export the same way errors do, so a handler
|
|
147
|
+
* that replaces everything it sees turns redirects into errors.
|
|
148
|
+
*
|
|
149
|
+
* Whatever is sent gets serialized to the client along with its own
|
|
150
|
+
* properties, so an error meant to be safe to expose must not carry
|
|
151
|
+
* internal detail.
|
|
152
|
+
*
|
|
153
|
+
* Type the export as `ServerFunctionErrorHandler` from
|
|
154
|
+
* `@solidjs/start/server`. The module is bundled into the server only, so
|
|
155
|
+
* it may import server-only code such as a monitoring SDK.
|
|
134
156
|
*
|
|
135
157
|
* @example "src/server-fn-error.ts"
|
|
136
158
|
*/
|
|
@@ -1,3 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Handles whatever a server function threw, before it reaches the client. Use
|
|
3
|
+
* it to type the default export of the module named by the
|
|
4
|
+
* `serverFunctions.onError` option in `vite.config.ts`.
|
|
5
|
+
*
|
|
6
|
+
* The handler may be asynchronous. SolidStart awaits its return value before
|
|
7
|
+
* sending the error to the client. If the handler throws or rejects, SolidStart
|
|
8
|
+
* sends the original thrown value instead.
|
|
9
|
+
*
|
|
10
|
+
* @param thrown The value the server function threw. This is a `Response` when
|
|
11
|
+
* the server function threw control flow such as a `redirect()`.
|
|
12
|
+
* @returns `undefined` (or `null`) to send `thrown` unchanged, a `Response` to
|
|
13
|
+
* preserve control flow, any other replacement value, or a promise resolving
|
|
14
|
+
* to any of those values.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* // src/server-fn-error.ts
|
|
19
|
+
* import type { ServerFunctionErrorHandler } from "@solidjs/start/server";
|
|
20
|
+
* import { captureException } from "./your-monitoring-client";
|
|
21
|
+
*
|
|
22
|
+
* const onServerFunctionError: ServerFunctionErrorHandler = thrown => {
|
|
23
|
+
* // redirect() throws a Response, so returning it preserves that control flow.
|
|
24
|
+
* if (thrown instanceof Response) return thrown;
|
|
25
|
+
*
|
|
26
|
+
* captureException(thrown); // or console.error, or any reporter
|
|
27
|
+
* return new Error("Something went wrong");
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* export default onServerFunctionError;
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
1
33
|
export type ServerFunctionErrorHandler = (thrown: unknown) => unknown;
|
|
2
|
-
|
|
3
|
-
export declare function applyServerFunctionErrorHandler(thrown: unknown): unknown;
|
|
34
|
+
export declare function applyServerFunctionErrorHandler(thrown: unknown): Promise<unknown>;
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import onServerFunctionError from "solid-start:server-fn-error-handler";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export async function applyServerFunctionErrorHandler(thrown) {
|
|
3
|
+
try {
|
|
4
|
+
const replacement = await onServerFunctionError?.(thrown);
|
|
5
|
+
return replacement ?? thrown;
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return thrown;
|
|
9
|
+
}
|
|
5
10
|
}
|
package/dist/fns/handler.js
CHANGED
|
@@ -125,7 +125,7 @@ export async function handleServerFunction(h3Event) {
|
|
|
125
125
|
return serializeToJSONStream(result);
|
|
126
126
|
}
|
|
127
127
|
catch (x) {
|
|
128
|
-
x = applyServerFunctionErrorHandler(x);
|
|
128
|
+
x = await applyServerFunctionErrorHandler(x);
|
|
129
129
|
if (x instanceof Response) {
|
|
130
130
|
if (singleFlight && instance) {
|
|
131
131
|
x = await handleSingleFlight(event, x);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@solidjs/start",
|
|
3
|
-
"version": "2.0.0-rc.
|
|
3
|
+
"version": "2.0.0-rc.8",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/solidjs/solid-start.git",
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"path-to-regexp": "^8.4.2",
|
|
49
49
|
"pathe": "^2.0.3",
|
|
50
50
|
"radix3": "^1.1.2",
|
|
51
|
-
"seroval": "^1.
|
|
52
|
-
"seroval-plugins": "^1.
|
|
51
|
+
"seroval": "^1.6.0",
|
|
52
|
+
"seroval-plugins": "^1.6.0",
|
|
53
53
|
"shiki": "^4.3.1",
|
|
54
54
|
"solid-js": "^1.9.14",
|
|
55
55
|
"source-map-js": "^1.2.1",
|