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
Support AbortController
#2020
Support AbortController
#2020
Conversation
It seems that |
See how we did it in sindresorhus/p-retry#59 |
CI is failing. You may need to just rebase from |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've done some logic changes. Previously the abort signal was only affecting the native HTTP stream, which is incorrect, because it doesn't abort the retry timeout (the request would fail though).
Can you fix the tests please?
Thanks for your review and for correcting this.
|
Why do you think so? |
This reverts commit 723b960.
I think the AbortError should be caught in But I noticed that I can simplify the code using the |
Thanks for letting me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. The only concern I have is the use of AbortSignal
global. I'm not sure if it breaks when someone uses @types/node
v14 in their project.
I think it would. I suggest we just use |
I think for setting the error And because |
The intention is that we will change to the native
Why is it not possible? |
I'm sorry, I was confused if I should throw a custom error here or native DOMException (when possible).
I thought using DOMException is not possible because I had thought AbortError should inherit |
I think this statement might need to be edited since AbortError doesn't have |
You can add a sentence below it noting the exception. |
source/core/errors.ts
Outdated
*/ | ||
export class AbortError extends RequestError { | ||
constructor(request: Request, error?: Error) { | ||
super('This operation was aborted.', {...error, code: 'ERR_ABORTED'}, request); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of cloning error
, please set this.code
like in errors above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since error
(abortsignal.reason) is optional here, it seems passing error
into the second argument of the constructor cause compile error.
// Compile error occurs
// Argument of type 'ErrnoException | undefined' is not assignable to parameter of type 'Partial<ErrnoException & { code?: string | undefined; }>'.
// Type 'undefined' is not assignable to type 'Partial<ErrnoException & { code?: string | undefined; }>'
super('This operation was aborted.', error, request);
this.code = 'ERR_ABORTED';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks for clarifying. In this case you can just skip this. Like so:
super('This operation was aborted.', {}, request);
this.name = 'AbortError';
this.code = 'ERR_ABORTED';
The reason is user accessible via controller.signal.reason
, so I don't think we need to expose it for now. That might be for #1953
Why is that? If we strip error metadata then people won't know which request was aborted except the fact that it was aborted. I'm -1 on this. |
That's a good point. I agree it's more important with context than the consistency of using DOMException. |
Friendly reminder: can you address #2020 (comment) please? |
Thanks :) |
Fixes #1511.
Thanks for this awesome lib! :)
I added
signal
option for supportingAbortController
.when
AbortController.abort
is called, throwsDOMException
in the promise ofasPromise.ts
.About tests, I copied, pasted and fixed
cancel.ts
toabort.ts
.I'd appreciate it if you could let me know if I made any mistakes.
Checklist