fix: Throw a TypeError instead of a AssertionError (#1199)
This commit is contained in:
parent
ef33a79874
commit
ee1a933096
2 changed files with 3 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in a new issue