Skip to content

Commit

Permalink
fix: only throw error responses (#1076)
Browse files Browse the repository at this point in the history
Fixes: #1072
  • Loading branch information
ronag authored Oct 27, 2021
1 parent 7b03c91 commit 48d9578
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/fetch/index.js
Original file line number Diff line number Diff line change
@@ -171,7 +171,7 @@ async function fetch (...args) {

// 3. If response is a network error, then reject p with a TypeError
// and terminate these substeps.
if (response.status === 0) {
if (response.type === 'error') {
p.reject(
Object.assign(new TypeError('fetch failed'), { cause: response.error })
)
4 changes: 2 additions & 2 deletions test/node-fetch/main.js
Original file line number Diff line number Diff line change
@@ -409,14 +409,14 @@ describe('node-fetch', () => {
})
})

xit('should treat broken redirect as ordinary response (manual)', () => {
it('should treat broken redirect as ordinary response (manual)', () => {
const url = `${base}redirect/no-location`
const options = {
redirect: 'manual'
}
return fetch(url, options).then(res => {
expect(res.url).to.equal(url)
expect(res.status).to.equal(301)
expect(res.status).to.equal(0)
expect(res.headers.get('location')).to.be.null
})
})

0 comments on commit 48d9578

Please sign in to comment.