@solidjs/start 2.0.0-rc.7 → 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
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
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
|
+
|
|
3
10
|
## 2.0.0-rc.7
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
package/dist/config/index.d.ts
CHANGED
|
@@ -131,14 +131,17 @@ export interface SolidStartOptions {
|
|
|
131
131
|
* straight to its caller, and errors from API routes never reach it
|
|
132
132
|
* either.
|
|
133
133
|
*
|
|
134
|
-
* The
|
|
135
|
-
*
|
|
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:
|
|
136
137
|
*
|
|
137
138
|
* - `undefined` (or `null`) sends what was thrown, unchanged.
|
|
138
139
|
* - A `Response` is passed through unchanged, which keeps a thrown
|
|
139
140
|
* `redirect()` working.
|
|
140
141
|
* - Any other value is sent in place of what was thrown, and the client
|
|
141
142
|
* call rejects with it.
|
|
143
|
+
* - If the handler throws or rejects, what the server function threw is
|
|
144
|
+
* sent unchanged.
|
|
142
145
|
*
|
|
143
146
|
* Control flow reaches the export the same way errors do, so a handler
|
|
144
147
|
* that replaces everything it sees turns redirects into errors.
|
|
@@ -147,10 +150,6 @@ export interface SolidStartOptions {
|
|
|
147
150
|
* properties, so an error meant to be safe to expose must not carry
|
|
148
151
|
* internal detail.
|
|
149
152
|
*
|
|
150
|
-
* The return value is not awaited, so make the export a plain function
|
|
151
|
-
* rather than an `async` one, and report failures with calls that do not
|
|
152
|
-
* need awaiting.
|
|
153
|
-
*
|
|
154
153
|
* Type the export as `ServerFunctionErrorHandler` from
|
|
155
154
|
* `@solidjs/start/server`. The module is bundled into the server only, so
|
|
156
155
|
* it may import server-only code such as a monitoring SDK.
|
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
* it to type the default export of the module named by the
|
|
4
4
|
* `serverFunctions.onError` option in `vite.config.ts`.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
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.
|
|
8
9
|
*
|
|
9
10
|
* @param thrown The value the server function threw. This is a `Response` when
|
|
10
11
|
* the server function threw control flow such as a `redirect()`.
|
|
11
12
|
* @returns `undefined` (or `null`) to send `thrown` unchanged, a `Response` to
|
|
12
|
-
*
|
|
13
|
-
*
|
|
13
|
+
* preserve control flow, any other replacement value, or a promise resolving
|
|
14
|
+
* to any of those values.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
16
17
|
* ```ts
|
|
@@ -30,4 +31,4 @@
|
|
|
30
31
|
* ```
|
|
31
32
|
*/
|
|
32
33
|
export type ServerFunctionErrorHandler = (thrown: unknown) => unknown;
|
|
33
|
-
export declare function applyServerFunctionErrorHandler(thrown: unknown): unknown
|
|
34
|
+
export declare function applyServerFunctionErrorHandler(thrown: unknown): Promise<unknown>;
|
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import onServerFunctionError from "solid-start:server-fn-error-handler";
|
|
2
|
-
export function applyServerFunctionErrorHandler(thrown) {
|
|
3
|
-
|
|
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
|
+
}
|
|
4
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);
|