Skip to content

Commit

Permalink
Merge 5480413 into ce7dbf3
Browse files Browse the repository at this point in the history
  • Loading branch information
simonratner committed Nov 19, 2015
2 parents ce7dbf3 + 5480413 commit 47795be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion index.js
Expand Up @@ -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];
}

Expand Down
19 changes: 19 additions & 0 deletions test/text.test.js
Expand Up @@ -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 () {});
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 47795be

Please sign in to comment.