Skip to content

Commit c9168d0

Browse files
committed
Add Cookie Error
When making a request via the event.fetch to the same exact domain the svelte app is running on, it fails returning a 500 due to the header being immutable. This only happens when a cookie is set in the hooks before trying to make a request with the event.fetch
1 parent d8b6133 commit c9168d0

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

packages/kit/src/runtime/server/cookie.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,19 @@ export function path_matches(path, constraint) {
274274
*/
275275
export function add_cookies_to_headers(headers, cookies) {
276276
for (const new_cookie of cookies) {
277-
const { name, value, options } = new_cookie;
278-
headers.append('set-cookie', serialize(name, value, options));
279-
280-
// special case — for routes ending with .html, the route data lives in a sibling
281-
// `.html__data.json` file rather than a child `/__data.json` file, which means
282-
// we need to duplicate the cookie
283-
if (options.path.endsWith('.html')) {
284-
const path = add_data_suffix(options.path);
285-
headers.append('set-cookie', serialize(name, value, { ...options, path }));
277+
try {
278+
const { name, value, options } = new_cookie;
279+
headers.append('set-cookie', serialize(name, value, options));
280+
281+
// special case — for routes ending with .html, the route data lives in a sibling
282+
// `.html__data.json` file rather than a child `/__data.json` file, which means
283+
// we need to duplicate the cookie
284+
if (options.path.endsWith('.html')) {
285+
const path = add_data_suffix(options.path);
286+
headers.append('set-cookie', serialize(name, value, { ...options, path }));
287+
}
288+
} catch (error) {
289+
console.error(`Failed to add cookie "${new_cookie.name}":`, error);
286290
}
287291
}
288292
}

0 commit comments

Comments
 (0)