fix: anchor fetchThrowsOn regexes to avoid false positives on 2xx/3xx#673
Open
andreahlert wants to merge 1 commit intobigskysoftware:devfrom
Open
fix: anchor fetchThrowsOn regexes to avoid false positives on 2xx/3xx#673andreahlert wants to merge 1 commit intobigskysoftware:devfrom
andreahlert wants to merge 1 commit intobigskysoftware:devfrom
Conversation
The default `fetchThrowsOn` patterns `/4.*/` and `/5.*/` are unanchored,
so any status code containing the digit 4 or 5 matches and throws.
This incorrectly fails 204, 304, 250-259, etc.
Anchor to `/^4/` and `/^5/` so only 4xx and 5xx throw, matching the
documented behavior ("fetch throws on non-2xx responses").
Fixes bigskysoftware#670
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Default
fetchThrowsOnpatterns are unanchored:/4.*/.test("204")returnstruebecause"4"appears at index 2. Same issue affects304,250-259, etc. Any 2xx/3xx response whose status string contains a4or5digit is incorrectly treated as an error and throwsfetch failed: <status> ....Fixes #670.
Repro
Server returns
204 No Content. Console:Docs say: "fetch throws on non-2xx responses (404, 500, etc.)" — current behavior contradicts that.
Fix
Anchor the regexes:
Tests
Added two cases in
test/commands/fetch.js:does not throw on 204 No Contentdoes not throw on 304 Not ModifiedAll 25 fetch tests pass.