-
-
Notifications
You must be signed in to change notification settings - Fork 100
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
AbortAddon: setTimeout
doesn't work in combination with own AbortController
instance
#256
Comments
Hey @adriaanmeuris, // Doesn't abort after 0.5 second timeout (even though configured so)
await wretch(url).addon(AbortAddon()).signal(controller).get().setTimeout(500); I believe you have to explicitly pass your custom controller as an argument:
https://elbywan.github.io/wretch/api/interfaces/addons_abort.AbortResolver.html#setTimeout
They are both equivalent indeed, since |
Thanks for clarifying. Is I need to distinguish manual aborts (e.g. aborting irrelevant requests before they resolve) from actual timeouts, especially for error reporting. Any advice on this, or would you consider a PR that allow to explicitly separate the two cases? |
Yes, otherwise the controller will not be associated with the request.
There is a way to specify a reason when aborting, maybe you could leverage that? Something like (reusing your example): const controller = new AbortController();
setTimeout(() => { controller.abort("custom reason"); }, 250);
try {
await wretch(url).addon(AbortAddon()).signal(controller).get().setTimeout(500, controller);
} catch (error) {
if (controller.signal.reason === "custom reason") {
// aborted manually
} else if (controller.signal.aborted) {
// aborted due to the timeout
} else {
// … //
}
} |
Timeouts and aborting requests work fine when using
.controller
:However when you want to provide a controller yourself, the implementation is broken:
Additionally, I don't this it's currently possible to differentiate between a configured timeout error, and manually aborting it (they both trigger the
onAborted
catcher)The text was updated successfully, but these errors were encountered: