-
-
Notifications
You must be signed in to change notification settings - Fork 956
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
Hook beforeError
does not respect the throwHttpErrors
setting
#2103
Comments
This unfortunately won't be easy to fix. In order to make a retry, an error is required. Then the It wasn't possible to retry streams until #1384 - to make the same logic there we would need to replace Lines 796 to 799 in 0947389
with if (options.isStream && !isResponseOk(typedResponse)) {
if (options.throwHttpErrors || (this.listenerCount('retry') > 0 && thisIsNotTheLastRetry)) {
this._beforeError(new HTTPError(typedResponse));
return;
}
} but since |
Also
|
We need to document this retry difference. |
#2104 is a potential fix. |
/cc @sindresorhus |
Describe the bug
18.0.0
Windows 10
,Raspbian Buster
,Ubuntu 20.04
11.6.0
and higherActual behavior
The
beforeError
hook fires regardless of whether or not thethrowHttpErrors
option is set tofalse
and the request fails. This has been (erroneously, it seems?) changed in #1384 - more specifically in as-promise/index.ts. This change wasn't mentioned anywhere in the11.6.0
release, or in other releases since.The behaviour is correct in all versions up until
11.6.0
, where this PR was merged.Expected behavior
The
beforeError
hook should not fire if thethrowHttpErrors
option is set tofalse
, and the request fails.Code to reproduce
In versions prior to
11.6.0
, the request response will be logged into console. In versions since, thebeforeError
hook will take precedence, log the error from it, and the response will not be logged.As an alternative to a code-based fix, the documentation could be adjusted instead, as it currently contains no reference to such behaviour.
Checklist
The text was updated successfully, but these errors were encountered: