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

Fix: when using Error.cause ensure older browsers/node still works #51

Merged
merged 10 commits into from
Sep 21, 2022

Conversation

belgattitude
Copy link
Owner

@belgattitude belgattitude commented Sep 21, 2022

Fix Error.cause on node < 16.9 and browsers that don't support for it.

  • Browser currently 89% support: caniuse#error.cause - (89% supports it as of sept 2022)
  • Node from 16.9.0 as per mdn.

The strategy used can be summarized as:

If the browser or the node runtime does not support Error.cause parameter in the
constructor, it will simply be discarded.
ie:

const err = new HttpNotFound({cause: new Error()});
console.log(err.cause) -> undefined if no support
console.log(err.cause) -> Error cause if supported

To enable older browser or previous node versions, there's 2 polyfills that should
do the job

@belgattitude belgattitude merged commit 377b3db into main Sep 21, 2022
@belgattitude belgattitude deleted the support-cause-legacy branch September 21, 2022 00:34
@belgattitude belgattitude mentioned this pull request Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant