Skip to content

Commit

Permalink
Merge 5af69c8 into f3c67d9
Browse files Browse the repository at this point in the history
  • Loading branch information
3imed-jaberi committed Apr 2, 2022
2 parents f3c67d9 + 5af69c8 commit f449d84
Show file tree
Hide file tree
Showing 5 changed files with 1,397 additions and 1,208 deletions.
2 changes: 1 addition & 1 deletion __tests__/application/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ describe('app.respond', () => {
describe('with custom status=700', () => {
it('should respond with the associated status message', async () => {
const app = new Koa()
statuses['700'] = 'custom status'
statuses.message['700'] = 'custom status'

app.use(ctx => {
ctx.status = 700
Expand Down
4 changes: 2 additions & 2 deletions lib/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ const proto = module.exports = {
if (err.code === 'ENOENT') statusCode = 404

// default to 500
if (typeof statusCode !== 'number' || !statuses[statusCode]) statusCode = 500
if (typeof statusCode !== 'number' || !statuses.message[statusCode]) statusCode = 500

// respond
const code = statuses[statusCode]
const code = statuses.message[statusCode]
const msg = err.expose ? err.message : code
this.status = err.status = statusCode
this.length = Buffer.byteLength(msg)
Expand Down
4 changes: 2 additions & 2 deletions lib/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ module.exports = {
assert(code >= 100 && code <= 999, `invalid status code: ${code}`)
this._explicitStatus = true
this.res.statusCode = code
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses[code]
if (this.req.httpVersionMajor < 2) this.res.statusMessage = statuses.message[code]
if (this.body && statuses.empty[code]) this.body = null
},

Expand All @@ -99,7 +99,7 @@ module.exports = {
*/

get message () {
return this.res.statusMessage || statuses[this.status]
return this.res.statusMessage || statuses.message[this.status]
},

/**
Expand Down

0 comments on commit f449d84

Please sign in to comment.