Skip to content

feat: expose original request on WretchError #265

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dirkluijk
Copy link

Closes #264

Copy link
Owner

@elbywan elbywan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dirkluijk Thanks a lot for the PR, and I'm sorry that I did not have time to review it earlier 🙇

The code looks good to me, the only issue is with node 14-16 / Request compatibility.

I am planning to release a new major version in a near future removing the burden of having all these legacy polyfills, but in the meantime how about setting the url/options as properties of the error instead of the request itself and let the consumer instantiate it?

Something like:

// Instead of setting the request
// err.request = new Request(finalUrl, finalRequestInit)
err.options = finalRequestInit

// (...)

try {
  // ... //
} catch (e) {
  console.log(e.response.url, e.options);
  const request = new Request(e.url, e.options);      
}

@@ -56,6 +59,7 @@ export const resolver = <T, Chain, R>(wretch: T & Wretch<T, Chain, R>) => {
err["cause"] = referenceError
err.stack = err.stack + "\nCAUSE: " + referenceError.stack
err.response = response
err.request = new Request(finalUrl, finalRequestInit)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current major version of wretch is compatible with node v14, so using Request without polyfill would break the contract.

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.

Access request in WretchError
2 participants