From 6a2ed3e6ebdb75238042188fab6002f3107c2d40 Mon Sep 17 00:00:00 2001 From: dead_horse Date: Fri, 25 Apr 2014 01:08:08 +0800 Subject: [PATCH] assert object type in ctx.onerror --- lib/context.js | 5 ++++- test/context/onerror.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/context.js b/lib/context.js index fdcc1e1..0511558 100644 --- a/lib/context.js +++ b/lib/context.js @@ -3,6 +3,7 @@ * Module dependencies. */ +var assert = require('assert'); var delegate = require('delegates'); var http = require('http'); @@ -86,7 +87,9 @@ var proto = module.exports = { // don't do anything if there is no error. // this allows you to pass `this.onerror` // to node-style callbacks. - if (!err) return; + if (undefined == err) return; + + assert(err instanceof Error, 'non-error thrown: ' + err); // nothing we can do here other // than delegate to the app-level diff --git a/test/context/onerror.js b/test/context/onerror.js index 65a9262..6bf9c85 100644 --- a/test/context/onerror.js +++ b/test/context/onerror.js @@ -50,4 +50,4 @@ describe('ctx.onerror(err)', function(){ done(); }) }) -}) \ No newline at end of file +})