@sveltejs/kit 1.2.4 → 1.2.5
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/package.json
CHANGED
|
@@ -24,9 +24,6 @@ export async function handle_action_json_request(event, options, server) {
|
|
|
24
24
|
const actions = server?.actions;
|
|
25
25
|
|
|
26
26
|
if (!actions) {
|
|
27
|
-
if (server) {
|
|
28
|
-
maybe_throw_migration_error(server);
|
|
29
|
-
}
|
|
30
27
|
// TODO should this be a different error altogether?
|
|
31
28
|
const no_actions_error = error(405, 'POST method not allowed. No actions exist for this page');
|
|
32
29
|
return action_json(
|
|
@@ -50,6 +47,10 @@ export async function handle_action_json_request(event, options, server) {
|
|
|
50
47
|
try {
|
|
51
48
|
const data = await call_action(event, actions);
|
|
52
49
|
|
|
50
|
+
if (__SVELTEKIT_DEV__) {
|
|
51
|
+
validate_action_return(data);
|
|
52
|
+
}
|
|
53
|
+
|
|
53
54
|
if (data instanceof ActionFailure) {
|
|
54
55
|
return action_json({
|
|
55
56
|
type: 'failure',
|
|
@@ -124,7 +125,6 @@ export async function handle_action_request(event, server) {
|
|
|
124
125
|
const actions = server.actions;
|
|
125
126
|
|
|
126
127
|
if (!actions) {
|
|
127
|
-
maybe_throw_migration_error(server);
|
|
128
128
|
// TODO should this be a different error altogether?
|
|
129
129
|
event.setHeaders({
|
|
130
130
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/405
|
|
@@ -142,13 +142,22 @@ export async function handle_action_request(event, server) {
|
|
|
142
142
|
try {
|
|
143
143
|
const data = await call_action(event, actions);
|
|
144
144
|
|
|
145
|
+
if (__SVELTEKIT_DEV__) {
|
|
146
|
+
validate_action_return(data);
|
|
147
|
+
}
|
|
148
|
+
|
|
145
149
|
if (data instanceof ActionFailure) {
|
|
146
|
-
return {
|
|
150
|
+
return {
|
|
151
|
+
type: 'failure',
|
|
152
|
+
status: data.status,
|
|
153
|
+
data: data.data
|
|
154
|
+
};
|
|
147
155
|
} else {
|
|
148
156
|
return {
|
|
149
157
|
type: 'success',
|
|
150
158
|
status: 200,
|
|
151
|
-
|
|
159
|
+
// @ts-expect-error this will be removed upon serialization, so `undefined` is the same as omission
|
|
160
|
+
data
|
|
152
161
|
};
|
|
153
162
|
}
|
|
154
163
|
} catch (e) {
|
|
@@ -185,7 +194,7 @@ function check_named_default_separate(actions) {
|
|
|
185
194
|
* @param {NonNullable<import('types').SSRNode['server']['actions']>} actions
|
|
186
195
|
* @throws {Redirect | ActionFailure | HttpError | Error}
|
|
187
196
|
*/
|
|
188
|
-
|
|
197
|
+
async function call_action(event, actions) {
|
|
189
198
|
const url = new URL(event.request.url);
|
|
190
199
|
|
|
191
200
|
let name = 'default';
|
|
@@ -213,16 +222,16 @@ export async function call_action(event, actions) {
|
|
|
213
222
|
return action(event);
|
|
214
223
|
}
|
|
215
224
|
|
|
216
|
-
/**
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
)
|
|
225
|
-
|
|
225
|
+
/** @param {any} data */
|
|
226
|
+
function validate_action_return(data) {
|
|
227
|
+
if (data instanceof Redirect) {
|
|
228
|
+
throw new Error(`Cannot \`return redirect(...)\` — use \`throw redirect(...)\` instead`);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
if (data instanceof HttpError) {
|
|
232
|
+
throw new Error(
|
|
233
|
+
`Cannot \`return error(...)\` — use \`throw error(...)\` or \`return fail(...)\` instead`
|
|
234
|
+
);
|
|
226
235
|
}
|
|
227
236
|
}
|
|
228
237
|
|