@sveltejs/kit 1.2.9 → 1.2.10
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
|
@@ -69,23 +69,23 @@ export async function handle_action_json_request(event, options, server) {
|
|
|
69
69
|
});
|
|
70
70
|
}
|
|
71
71
|
} catch (e) {
|
|
72
|
-
const
|
|
72
|
+
const err = normalize_error(e);
|
|
73
73
|
|
|
74
|
-
if (
|
|
74
|
+
if (err instanceof Redirect) {
|
|
75
75
|
return action_json({
|
|
76
76
|
type: 'redirect',
|
|
77
|
-
status:
|
|
78
|
-
location:
|
|
77
|
+
status: err.status,
|
|
78
|
+
location: err.location
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
return action_json(
|
|
83
83
|
{
|
|
84
84
|
type: 'error',
|
|
85
|
-
error: await handle_error_and_jsonify(event, options, check_incorrect_fail_use(
|
|
85
|
+
error: await handle_error_and_jsonify(event, options, check_incorrect_fail_use(err))
|
|
86
86
|
},
|
|
87
87
|
{
|
|
88
|
-
status:
|
|
88
|
+
status: err instanceof HttpError ? err.status : 500
|
|
89
89
|
}
|
|
90
90
|
);
|
|
91
91
|
}
|
|
@@ -110,19 +110,18 @@ function action_json(data, init) {
|
|
|
110
110
|
|
|
111
111
|
/**
|
|
112
112
|
* @param {import('types').RequestEvent} event
|
|
113
|
-
* @param {import('types').SSRNode} leaf_node
|
|
114
113
|
*/
|
|
115
|
-
export function is_action_request(event
|
|
116
|
-
return
|
|
114
|
+
export function is_action_request(event) {
|
|
115
|
+
return event.request.method === 'POST';
|
|
117
116
|
}
|
|
118
117
|
|
|
119
118
|
/**
|
|
120
119
|
* @param {import('types').RequestEvent} event
|
|
121
|
-
* @param {import('types').SSRNode['server']} server
|
|
120
|
+
* @param {import('types').SSRNode['server'] | undefined} server
|
|
122
121
|
* @returns {Promise<import('types').ActionResult>}
|
|
123
122
|
*/
|
|
124
123
|
export async function handle_action_request(event, server) {
|
|
125
|
-
const actions = server
|
|
124
|
+
const actions = server?.actions;
|
|
126
125
|
|
|
127
126
|
if (!actions) {
|
|
128
127
|
// TODO should this be a different error altogether?
|
|
@@ -161,19 +160,19 @@ export async function handle_action_request(event, server) {
|
|
|
161
160
|
};
|
|
162
161
|
}
|
|
163
162
|
} catch (e) {
|
|
164
|
-
const
|
|
163
|
+
const err = normalize_error(e);
|
|
165
164
|
|
|
166
|
-
if (
|
|
165
|
+
if (err instanceof Redirect) {
|
|
167
166
|
return {
|
|
168
167
|
type: 'redirect',
|
|
169
|
-
status:
|
|
170
|
-
location:
|
|
168
|
+
status: err.status,
|
|
169
|
+
location: err.location
|
|
171
170
|
};
|
|
172
171
|
}
|
|
173
172
|
|
|
174
173
|
return {
|
|
175
174
|
type: 'error',
|
|
176
|
-
error: check_incorrect_fail_use(
|
|
175
|
+
error: check_incorrect_fail_use(err)
|
|
177
176
|
};
|
|
178
177
|
}
|
|
179
178
|
}
|
|
@@ -59,7 +59,7 @@ export async function render_page(event, route, page, options, manifest, state,
|
|
|
59
59
|
/** @type {import('types').ActionResult | undefined} */
|
|
60
60
|
let action_result = undefined;
|
|
61
61
|
|
|
62
|
-
if (is_action_request(event
|
|
62
|
+
if (is_action_request(event)) {
|
|
63
63
|
// for action requests, first call handler in +page.server.js
|
|
64
64
|
// (this also determines status code)
|
|
65
65
|
action_result = await handle_action_request(event, leaf_node.server);
|
|
@@ -85,7 +85,7 @@ export async function render_page(event, route, page, options, manifest, state,
|
|
|
85
85
|
|
|
86
86
|
if (should_prerender) {
|
|
87
87
|
const mod = leaf_node.server;
|
|
88
|
-
if (mod
|
|
88
|
+
if (mod?.actions) {
|
|
89
89
|
throw new Error('Cannot prerender pages with actions');
|
|
90
90
|
}
|
|
91
91
|
} else if (state.prerendering) {
|