Skip to content

Commit

Permalink
fix: fetch response status text (#2588)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikicho committed Feb 17, 2024
1 parent 8605dae commit 11adf2c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/create_response.js
@@ -1,6 +1,7 @@
'use strict'

const { headersArrayToObject } = require('./common')
const { STATUS_CODES } = require('http')

/**
* Creates a Fetch API `Response` instance from the given
Expand Down Expand Up @@ -37,7 +38,7 @@ function createResponse(message) {

return new Response(responseBodyOrNull, {
status: message.statusCode,
statusText: message.statusMessage,
statusText: STATUS_CODES[message.statusCode],
headers: headersArrayToObject(message.rawHeaders),
})
}
Expand Down
8 changes: 8 additions & 0 deletions tests/test_fetch.js
Expand Up @@ -90,4 +90,12 @@ describe('Native Fetch', () => {
const { status } = await fetch('https://example.test')
expect(status).to.equal(200)
})

it('should set the statusText according to the response code', async () => {
nock('https://example.test').get('/').reply(404)

const { status, statusText } = await fetch('https://example.test')
expect(status).to.equal(404)
expect(statusText).to.equal('Not Found')
})
})

0 comments on commit 11adf2c

Please sign in to comment.