diff --git a/HISTORY.md b/HISTORY.md index 5e36579..9c5f528 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,6 +1,7 @@ unreleased ================== + * fix: use the status code as the error body when it has no name * deps: * debug@^4.4.3 * statuses@^2.0.2 diff --git a/index.js b/index.js index 862421c..e1e4a6e 100644 --- a/index.js +++ b/index.js @@ -167,7 +167,7 @@ function getErrorMessage (err, status, env) { } } - return msg || statuses.message[status] + return msg || statuses.message[status] || String(status) } /** diff --git a/package.json b/package.json index de69a68..596bc89 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "eslint-plugin-standard": "^4.1.0", "mocha": "^11.0.1", "nyc": "^17.1.0", - "supertest": "^7.0.0" + "supertest": "7.3.0" }, "files": [ "index.js" diff --git a/test/test.js b/test/test.js index 516e088..c463b3b 100644 --- a/test/test.js +++ b/test/test.js @@ -351,6 +351,17 @@ var topDescribe = function (type, createServer) { .expect(501, /
Not Implemented<\/pre>/, done)
})
+ it('should send status code when production and no status code name', function (done) {
+ var err = createError('boom!', {
+ status: 499
+ })
+ wrapper(request(createServer(err, {
+ env: 'production'
+ }))
+ .get('/foo'))
+ .expect(499, /499<\/pre>/, done)
+ })
+
describe('when there is a request body', function () {
it('should not hang/error when unread', function (done) {
var buf = Buffer.alloc(1024 * 16, '.')