Skip to content

Commit b232c47

Browse files
authored
fix(ext/runtime/http): record error if respondWith propagates exception (#643)
* fix(ext/runtime/http): record error if `respondWith` propagates exception * chore(examples): update `README.md` * chore: update `format.js`
1 parent 377bf71 commit b232c47

File tree

3 files changed

+24
-8
lines changed

3 files changed

+24
-8
lines changed

examples/custom-jwt-validation/README.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,26 @@
22

33
This function exemplifies how to use a custom JWT validation.
44

5-
Since Supabase legacy JWT Secret will be deprecated, users that would like to verify JWT or integrate with a custom provider should implement it manually.
6-
> see [Upcoming changes to Supabase API Keys #29260](https://github.com/orgs/supabase/discussions/29260)
5+
Since Supabase legacy JWT Secret will be deprecated, users that would like to
6+
verify JWT or integrate with a custom provider should implement it manually.
7+
8+
> see
9+
> [Upcoming changes to Supabase API Keys #29260](https://github.com/orgs/supabase/discussions/29260)
710
811
To simplify this task, Supabase provides a collection of JWT validation examples
9-
that can be found at [`_shared/jwt/`](https://github.com/supabase/edge-runtime/blob/main/examples/_shared/jwt) folder.
12+
that can be found at
13+
[`_shared/jwt/`](https://github.com/supabase/edge-runtime/blob/main/examples/_shared/jwt)
14+
folder.
1015

1116
## Setup
1217

13-
1. Copy/download the JWT template, then import and use it inside your edge function.
18+
1. Copy/download the JWT template, then import and use it inside your edge
19+
function.
1420

1521
```bash
1622
wget https://raw.githubusercontent.com/supabase/edge-runtime/refs/heads/main/examples/_shared/jwt/<template>.ts
1723
```
1824

1925
2. Add any required Environment-Variable to a `.env` file, see inside of the
20-
respective `_shared/jwt/template.ts` file to find which variables is required.
26+
respective `_shared/jwt/template.ts` file to find which variables is
27+
required.

ext/runtime/js/http.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,17 @@ function serveHttp(conn) {
9999
streamRid: nextRequest.streamRid,
100100
};
101101

102-
return nextRequest;
102+
return {
103+
...nextRequest,
104+
respondWith: async function (resp) {
105+
try {
106+
return await nextRequest.respondWith(resp);
107+
} catch (error) {
108+
console.error(error);
109+
throw error;
110+
}
111+
},
112+
};
103113
};
104114

105115
httpConn.close = () => {
@@ -271,7 +281,6 @@ async function respond(requestEvent, httpConn, options, snapshot) {
271281
}),
272282
);
273283
} catch (error) {
274-
console.error(error);
275284
closeHttpConn(httpConn);
276285
}
277286
});

scripts/format.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env -S deno run --allow-all
1+
#!/usr/bin/env -S deno run --allow-write --allow-read --allow-run --allow-net
22
// Copyright 2018-2025 the Deno authors. MIT license.
33

44
import { dirname, fromFileUrl, join } from "jsr:@std/path";

0 commit comments

Comments
 (0)