@@ -121,7 +121,7 @@ function Request(method, url) {
121121 this . _buffer = true ;
122122 this . attachments = [ ] ;
123123 this . on ( 'response' , function ( res ) {
124- self . callback ( res ) ;
124+ self . callback ( null , res ) ;
125125 } ) ;
126126}
127127
@@ -380,7 +380,7 @@ Request.prototype.redirect = function(res){
380380 this . _data = null ;
381381 this . url = url ;
382382 this . emit ( 'redirect' , res ) ;
383- this . end ( this . callback ) ;
383+ this . end ( this . _callback ) ;
384384 return this ;
385385} ;
386386
@@ -468,6 +468,21 @@ Request.prototype.request = function(){
468468 return req ;
469469} ;
470470
471+ /**
472+ * Invoke the callback with `err` and `res`
473+ * and handle arity check.
474+ *
475+ * @param {Error } err
476+ * @param {Response } res
477+ * @api private
478+ */
479+
480+ Request . prototype . callback = function ( err , res ) {
481+ var fn = this . _callback ;
482+ if ( 2 == fn . length ) return fn ( err , res ) ;
483+ fn ( res ) ; // TODO: emit error
484+ } ;
485+
471486/**
472487 * Initiate request, invoking callback `fn(err, res)`
473488 * with an instanceof `Response`.
@@ -485,7 +500,7 @@ Request.prototype.end = function(fn){
485500 , method = this . method ;
486501
487502 // store callback
488- this . callback = fn || noop ;
503+ this . _callback = fn || noop ;
489504
490505 // body
491506 switch ( method ) {
@@ -536,7 +551,7 @@ Request.prototype.end = function(fn){
536551 response . body = fields ;
537552 response . files = files ;
538553 self . emit ( 'end' ) ;
539- self . callback ( response ) ;
554+ self . callback ( null , response ) ;
540555 } ) ;
541556 return ;
542557 }
0 commit comments