diff --git a/lib/response.js b/lib/response.js index 13855c8..45c9626 100644 --- a/lib/response.js +++ b/lib/response.js @@ -3,15 +3,15 @@ * Module dependencies. */ +var ensureErrorHandler = require('error-inject'); var debug = require('debug')('koa:response'); var escape = require('escape-html'); +var onfinish = require('finished'); var status = require('statuses'); +var destroy = require('dethroy'); var http = require('http'); var path = require('path'); var mime = require('mime'); -var onFinished = require('finished'); -var destroy = require('dethroy'); -var inject = require('error-inject'); var basename = path.basename; var extname = path.extname; @@ -132,12 +132,8 @@ module.exports = { // stream if ('function' == typeof val.pipe) { - // make sure all intermediate streams will destroy on finished - onFinished(this, destroy.bind(null, val)); - - // make sure all intermediate streams has an listenner on error - inject(val, this.ctx.onerror); - + onfinish(this, destroy.bind(null, val)); + ensureErrorHandler(val, this.ctx.onerror); if (setType) this.type = 'bin'; return; }