non-error thrown, fixed #432

This commit is contained in:
dead_horse 2015-04-14 10:30:19 +08:00
parent c307c81c43
commit b6aea969f8
2 changed files with 19 additions and 2 deletions

View file

@ -7,7 +7,6 @@ var createError = require('http-errors');
var httpAssert = require('http-assert'); var httpAssert = require('http-assert');
var delegate = require('delegates'); var delegate = require('delegates');
var statuses = require('statuses'); var statuses = require('statuses');
var assert = require('assert');
/** /**
* Context prototype. * Context prototype.
@ -103,7 +102,7 @@ var proto = module.exports = {
// to node-style callbacks. // to node-style callbacks.
if (null == err) return; if (null == err) return;
assert(err instanceof Error, 'non-error thrown: ' + err); if (!(err instanceof Error)) err = new Error('non-error thrown: ' + err);
// delegate // delegate
this.app.emit('error', err, this); this.app.emit('error', err, this);

View file

@ -93,4 +93,22 @@ describe('ctx.onerror(err)', function(){
}) })
}) })
}) })
describe('when non-error thrown', function(){
it('should response non-error thrown message', function(done){
var app = koa();
app.use(function *(next){
throw 'string error';
})
var server = app.listen();
request(server)
.get('/')
.expect(500)
.expect('Content-Type', 'text/plain; charset=utf-8')
.expect('Internal Server Error', done);
})
})
}) })