It is a SuperAgent "issue" in how they've chosen to handle the function that is passed as the callback. If that function is expecting exactly two arguments as reported by the length property, then the "traditional" err
and res
are given like Async would like. If the function you pass does not report its length to be two, then the first argument given is res
. Here's SuperAgent's source for handling callbacks:
Request.prototype.callback = function(err, res){
var fn = this._callback;
if (2 == fn.length) return fn(err, res);
if (err) return this.emit('error', err);
fn(res);
};
To guarantee that your callbacks are invoked as intended, I would suggest passing an anonymous function to end
so that it definitely reports its length as two so you can get any errors passed to your callback.
request = require 'superagent'
user = request.agent()
async.waterfall [
(cb) ->
user.post('http://localhost:3000/form').send(name: 'Bob').end (err, res) ->
cb err, res
(err, res) ->
# err should be undefined if the request is successful
# res should be the response
cb null, res
], (err, res) ->
console.log err # this should now be null
console.log res # this should now be the response