fix: Throw a TypeError instead of a AssertionError (#1199)

This commit is contained in:
initial-wu 2018-06-06 12:55:20 +08:00 committed by Yiyu He
parent ef33a79874
commit ee1a933096
2 changed files with 3 additions and 4 deletions

View file

@ -17,7 +17,7 @@ const statuses = require('statuses');
const Cookies = require('cookies');
const accepts = require('accepts');
const Emitter = require('events');
const assert = require('assert');
const util = require('util');
const Stream = require('stream');
const http = require('http');
const only = require('only');
@ -185,7 +185,7 @@ module.exports = class Application extends Emitter {
*/
onerror(err) {
assert(err instanceof Error, `non-error thrown: ${err}`);
if (!(err instanceof Error)) throw new TypeError(util.format('non-error thrown: %j', err));
if (404 == err.status || err.expose) return;
if (this.silent) return;

View file

@ -3,7 +3,6 @@
const assert = require('assert');
const Koa = require('../..');
const AssertionError = require('assert').AssertionError;
describe('app.onerror(err)', () => {
beforeEach(() => {
@ -19,7 +18,7 @@ describe('app.onerror(err)', () => {
assert.throws(() => {
app.onerror('foo');
}, AssertionError, 'non-error thrown: foo');
}, TypeError, 'non-error thrown: foo');
});
it('should do nothing if status is 404', () => {