// So you can `var request = require("superagent-es6-promise")`
var superagent = module.exports = require("superagent");
superagent.Promise = Promise;
var Request = superagent.Request;

// Create custom error type.
// Create a new object, that prototypally inherits from the Error constructor.
var SuperagentPromiseError = superagent.SuperagentPromiseError = function (message) {
  this.name = 'SuperagentPromiseError';
  this.message = message || 'Bad request';
};

SuperagentPromiseError.prototype = new Error();
SuperagentPromiseError.prototype.constructor = SuperagentPromiseError;

/**
 * @namespace utils
 * @class Superagent
 */

/**
 *
 * Add promise support for superagent/supertest
 *
 * Call .promise() to return promise for the request
 *
 * @method then
 * @return {Promise}
 */
Request.prototype.promise = function() {
  var req = this;
  var error;

  return new superagent.Promise(function(resolve, reject) {
      req.end(function(err, res) {
        if (err) {
          error = new SuperagentPromiseError(msg);
          error.status = res.status;
          error.body = res.body;
          error.res = res;
          reject(error);
        } else {
          resolve(res);
        }
      });
    });
};

/**
 *
 * Make superagent requests Promises/A+ conformant
 *
 * Call .then([onFulfilled], [onRejected]) to register callbacks
 *
 * @method then
 * @param {function} [onFulfilled]
 * @param {function} [onRejected]
 * @return {Bluebird.Promise}
 */
Request.prototype.then = function() {
  var promise = this.promise();
  return promise.then.apply(promise, arguments);
};

@@ -1023,16 +1023,39 @@
 r(msg);%0A
+          if (res) %7B%0A  
         
@@ -1083,16 +1083,18 @@
 status;%0A
+  
         
@@ -1124,24 +1124,26 @@
 ;%0A          
+  
 error.res = 
@@ -1147,16 +1147,28 @@
  = res;%0A
+          %7D%0A
         

change error