Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a passThroughOnException() handler to Pages Functions #2111

Merged

Conversation

GregBrimble
Copy link
Contributor

Workers Types PR: cloudflare/workers-types#314

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:

export const onRequest = ({ passThroughOnException }) => {
	passThroughOnException();
	x; // Would ordinarily throw an error, but instead, static assets are served.
};

@GregBrimble GregBrimble added the pages Relating to Pages label Nov 1, 2022
@GregBrimble GregBrimble requested a review from a team November 1, 2022 14:53
@changeset-bot
Copy link

changeset-bot bot commented Nov 1, 2022

🦋 Changeset detected

Latest commit: 4a42336

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Nov 1, 2022

A wrangler prerelease is available for testing. You can install this latest build in your project with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/runs/3371303285/npm-package-wrangler-2111

You can reference the automatically updated head of this PR with:

npm install --save-dev https://prerelease-registry.developers.workers.dev/prs/2111/npm-package-wrangler-2111

Or you can use npx with this latest build directly:

npx https://prerelease-registry.developers.workers.dev/runs/3371303285/npm-package-wrangler-2111 dev path/to/script.js
Additional artifacts:
npm install https://prerelease-registry.developers.workers.dev/runs/3371303285/npm-package-cloudflare-pages-shared-2111

@codecov
Copy link

codecov bot commented Nov 1, 2022

Codecov Report

Merging #2111 (4a42336) into main (71cc524) will increase coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #2111      +/-   ##
==========================================
+ Coverage   73.17%   73.18%   +0.01%     
==========================================
  Files         128      128              
  Lines        8631     8631              
  Branches     2264     2264              
==========================================
+ Hits         6316     6317       +1     
+ Misses       2315     2314       -1     
Impacted Files Coverage Δ
...ackages/wrangler/src/__tests__/helpers/mock-bin.ts 100.00% <0.00%> (+5.26%) ⬆️

@GregBrimble GregBrimble force-pushed the monkey-patch-pages-functions-passthroughonexception branch from e28588c to 4a42336 Compare November 1, 2022 17:03
@GregBrimble GregBrimble merged commit ab52f77 into main Nov 2, 2022
@GregBrimble GregBrimble deleted the monkey-patch-pages-functions-passthroughonexception branch November 2, 2022 10:24
@github-actions github-actions bot mentioned this pull request Nov 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pages Relating to Pages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants