diff --git a/index.js b/index.js index 7874273..9639934 100644 --- a/index.js +++ b/index.js @@ -122,7 +122,7 @@ function onerror(app, options) { this.res._headers = {}; this.body = isDev || err.expose - ? err.message + ? err.message || http.STATUS_CODES[this.status] : http.STATUS_CODES[this.status]; } diff --git a/test/text.test.js b/test/text.test.js index fd43da8..4607db5 100644 --- a/test/text.test.js +++ b/test/text.test.js @@ -42,6 +42,18 @@ describe('text.test.js', function () { .expect('this message will be expose', done); }); + it('should show default message if undefined', function (done) { + var app = koa(); + app.on('error', function () {}); + onerror(app); + app.use(exposeBlankError); + + request(app.callback()) + .get('/') + .set('Accept', 'text/plain') + .expect(500, done); + }); + it('should stream error ok', function (done) { var app = koa(); app.on('error', function () {}); @@ -80,6 +92,13 @@ function* exposeError() { throw err; } +function* exposeBlankError() { + var err = new Error(); + err.message = undefined; + err.expose = true; + throw err; +} + function* commonError() { foo(); }