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 Cookies = require('cookies');
|
||||||
const accepts = require('accepts');
|
const accepts = require('accepts');
|
||||||
const Emitter = require('events');
|
const Emitter = require('events');
|
||||||
const assert = require('assert');
|
const util = require('util');
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const http = require('http');
|
const http = require('http');
|
||||||
const only = require('only');
|
const only = require('only');
|
||||||
|
@ -185,7 +185,7 @@ module.exports = class Application extends Emitter {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
onerror(err) {
|
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 (404 == err.status || err.expose) return;
|
||||||
if (this.silent) return;
|
if (this.silent) return;
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
const assert = require('assert');
|
const assert = require('assert');
|
||||||
const Koa = require('../..');
|
const Koa = require('../..');
|
||||||
const AssertionError = require('assert').AssertionError;
|
|
||||||
|
|
||||||
describe('app.onerror(err)', () => {
|
describe('app.onerror(err)', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -19,7 +18,7 @@ describe('app.onerror(err)', () => {
|
||||||
|
|
||||||
assert.throws(() => {
|
assert.throws(() => {
|
||||||
app.onerror('foo');
|
app.onerror('foo');
|
||||||
}, AssertionError, 'non-error thrown: foo');
|
}, TypeError, 'non-error thrown: foo');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should do nothing if status is 404', () => {
|
it('should do nothing if status is 404', () => {
|
||||||
|
|
Loading…
Reference in a new issue