Skip to content

Commit 5c52f04

Browse files
authored
fix: Explicitly implement error bypass behavior instead of relying on the platform (#123)
In this patch we are changing the function to catch all the throws and return undefined in those situations. The reason we do this is because returning undefined will cause the next edge function in the chain to be executed. This is equivalent to setting the Edge Function's `config.onError` property to "bypass", but is handled completely by the Edge Function instead of by something else.
1 parent 10997a9 commit 5c52f04

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/__csp-nonce.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,23 @@ params.https = true;
3131
params.http = true;
3232

3333
const handler = async (_request: Request, context: Context) => {
34-
const response = await context.next();
35-
36-
// for debugging which routes use this edge function
37-
response.headers.set("x-debug-csp-nonce", "invoked");
38-
return csp(response, params);
34+
try {
35+
const response = await context.next();
36+
// for debugging which routes use this edge function
37+
response.headers.set("x-debug-csp-nonce", "invoked");
38+
return csp(response, params);
39+
} catch {
40+
/*
41+
We catch all the throws and return undefined
42+
The reason we do this is because returning undefined
43+
will cause the next edge function in the chain to be
44+
executed.
45+
This is equivalent to setting the Edge Function's
46+
`config.onError` property to "bypass", but is handled
47+
completely by the Edge Function instead of by something else.
48+
*/
49+
return void 0;
50+
}
3951
};
4052

4153
// Top 50 most common extensions (minus .html and .htm) according to Humio

0 commit comments

Comments
 (0)