-
Notifications
You must be signed in to change notification settings - Fork 770
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a
passThroughOnException()
handler to Pages Functions
- Loading branch information
1 parent
71cc524
commit 4a42336
Showing
10 changed files
with
123 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
--- | ||
"wrangler": patch | ||
--- | ||
|
||
feat: Add a `passThroughOnException()` handler in Pages Functions | ||
|
||
This `passThroughOnException()` handler is not as good as the built-in for Workers. We're just adding it now as a stop-gap until we can do the behind-the-scenes plumbing required to make the built-in function work properly. | ||
|
||
We wrap your Pages Functions code in a `try/catch` and on failure, if you call `passThroughOnException()` we defer to the static assets of your project. | ||
|
||
For example: | ||
|
||
```ts | ||
export const onRequest = ({ passThroughOnException }) => { | ||
passThroughOnException(); | ||
|
||
x; // Would ordinarily throw an error, but instead, static assets are served. | ||
}; | ||
``` |
5 changes: 5 additions & 0 deletions
5
fixtures/pages-functions-app/functions/passThroughOnException/_middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const onRequest = ({ passThroughOnException, next }) => { | ||
passThroughOnException(); | ||
|
||
return next(); | ||
}; |
3 changes: 3 additions & 0 deletions
3
fixtures/pages-functions-app/functions/passThroughOnException/nested.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const onRequest = ({ passThroughOnException }) => { | ||
x; | ||
}; |
3 changes: 3 additions & 0 deletions
3
fixtures/pages-functions-app/functions/passThroughOnExceptionClosed.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const onRequest = ({ passThroughOnException }) => { | ||
x; | ||
}; |
5 changes: 5 additions & 0 deletions
5
fixtures/pages-functions-app/functions/passThroughOnExceptionOpen.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export const onRequest = ({ passThroughOnException }) => { | ||
passThroughOnException(); | ||
|
||
x; | ||
}; |
13 changes: 13 additions & 0 deletions
13
fixtures/pages-functions-app/functions/passThroughOnExceptionWithCapture/_middleware.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const onRequest = async ({ request, passThroughOnException, next }) => { | ||
passThroughOnException(); | ||
|
||
try { | ||
return await next(); | ||
} catch (e) { | ||
if (new URL(request.url).searchParams.has("catch")) { | ||
return new Response(`Manually caught error: ${e}`); | ||
} | ||
|
||
throw e; | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
fixtures/pages-functions-app/functions/passThroughOnExceptionWithCapture/nested.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const onRequest = ({ passThroughOnException }) => { | ||
x; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters