Skip to content

Commit b1d6380

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 b1d6380

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

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

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -274,15 +274,20 @@ 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+
279+
const { name, value, options } = new_cookie;
280+
headers.append('set-cookie', serialize(name, value, options));
281+
282+
// special case — for routes ending with .html, the route data lives in a sibling
283+
// `.html__data.json` file rather than a child `/__data.json` file, which means
284+
// we need to duplicate the cookie
285+
if (options.path.endsWith('.html')) {
286+
const path = add_data_suffix(options.path);
287+
headers.append('set-cookie', serialize(name, value, { ...options, path }));
288+
}
289+
} catch (error) {
290+
console.error(`Failed to add cookie "${new_cookie.name}":`, error);
286291
}
287292
}
288293
}

0 commit comments

Comments
 (0)