Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

supportAbortSignal.reason#1775

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
gomain wants to merge1 commit intonode-fetch:main
base:main
Choose a base branch
Loading
fromgomain:support-abort-reason

Conversation

@gomain
Copy link

In enviroments that implement it.

When anAbortSignal#reason has a value, i.e. in nodejs >= v17.2.0, it is added on the returnedAbortError.AbortError#reason would beundefined otherwise.

Contrary to the specification, whenAbortController#abort is called, with or without a reason,fetchdoes not throw theAbortSignal#reason. This is to allow more fine grained error handling. Had thereason was thrown, the general information that an abort happened is lost and it becomes sole responsibility of the reason provider.

Purpose

Allow detecting thereason fetch was aborted.

Changes

  • ExtendAbortError to have fieldreason. It's constructor takes this additional argument.
  • TheAbortSignal#reason is given when constructingAbortError instance. Could possibly beundefined in environments/libraries/polyfills that do not support it.

Additional information

The actual value (even existence) ofAbortSignal#reason is external to this library. We make no assumptions about it. We simply forward it.

This goes against#1519. There is no inherent reason to follow the specifications to the dot.node-fetch is for node, specifically, not the web. TBD.


  • I updated readme
  • I added unit test(s)

In enviroments that implement it.When an `AbortSignal#reason` has a value, i.e. in nodejs >= v17.2.0,it is added on the returned `AbortError`. `AbortError#reason` would be`undefined` otherwise.Contary to the specification, when `AbortController#abort` is called,with or without a reason, `fetch` _does not_ throw the`AbortSignal#reason`.
* AbortError interface for cancelled requests
*/
exportclassAbortErrorextendsFetchBaseError{
constructor(message,type='aborted'){
Copy link
Member

Choose a reason for hiding this comment

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

Is this a breaking change?

AbortError is exported publicly from the package...

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, wasn't aware the constructor was actually exported. It just seemed odd that thetype would be explicitly given, i.e. what else could it be.

We basically need to thread thereason into the thrownAbortError. To not break its constructor, the only sane option would be to extend it:

// no change to existing `AbortError`classAbortWithReasonErrorextendsAbortError{constructor(message,reason){super(message);this.reason=reason;}}

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@LinusULinusULinusU left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AbortController abort reason Parameter

2 participants

@gomain@LinusU

[8]ページ先頭

©2009-2025 Movatter.jp