Skip to content

Commit 7ae7cfd

Browse files
fix(cf-function): guard against null metadata to prevent 502s
When the KV store returns null/undefined for the metadata key — which can happen transiently during deployment as the KV entry propagates to edge nodes — routeSite throws an uncaught TypeError accessing metadata.base, causing CloudFront to return a 502. This is most visible when errorPage is configured, because that disables the function-level custom404 fallback in favour of distribution-level customErrorResponses. The 502 manifests inconsistently because only some edge nodes are affected during the propagation window. The fix fails open: if metadata is unavailable, pass the request through to the default origin unchanged rather than crashing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3b0c5c4 commit 7ae7cfd

2 files changed

Lines changed: 2 additions & 0 deletions

File tree

platform/src/components/aws/ssr-site.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@ async function handler(event) {
943943
metadata = JSON.parse(v);
944944
} catch (e) {}
945945
946+
if (!metadata) return event.request;
946947
const response = await routeSite(kvNamespace, metadata);
947948
return response || event.request;
948949
}`,

platform/src/components/aws/static-site.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,7 @@ async function handler(event) {
11291129
metadata = JSON.parse(v);
11301130
} catch (e) {}
11311131
1132+
if (!metadata) return event.request;
11321133
const response = await routeSite(kvNamespace, metadata);
11331134
return response || event.request;
11341135
}`,

0 commit comments

Comments
 (0)