title: Node.js promise with q not working as expected
body: <p>this is my approach:</p>
  
  <pre><code>var q = require('q');
  var request = require("request");
  
  exports.route = function (req, res) {
      var userId = req.query.userId;
  
      if (!userId) {
          res.send(JSON.stringify({
              errorCode: 400,
              error: "userId is missing, please form your query like &lt;url&gt;/avatar?userId=00.42.1"
          }), 400);
          return;
      }
      getAvatar(userId).then(function (success) {
              console.log('success');
              res.json(success);
          }, function (error) {
              console.log('error');
              res.json({error: error});
          }
      );
  
  
  };
  
  function getAvatar(userId) {
      var isErrorInResponse = function (error, response) {
          return typeof error !== 'undefined' || error == null || response.statusCode &gt; 202;
      };
  
      var deferred = q.defer();
      var url = "http://localhost/avatar" + userId;
      console.log(url);
      request(url, function (error, response, body) {
          if (isErrorInResponse(error, response)) {
              deferred.reject(new Error({error: error, response: response, body: body}));
          } else {
              deferred.resolve(body);
          }
      });
      return deferred.promise;
  };
  </code></pre>
  
  <p><code>GET localhost:8090/avatar?userId=42 produces</code> following log:</p>
  
  <pre><code>http://localhost/avatar/42
  error
  </code></pre>
  
  <p>and sends this response to the client:</p>
  
  <pre><code>{
    "error": {}
  }
  </code></pre>
  
  <p>And here is my versions, which I'm not able to update:</p>
  
  <pre><code> "dependencies": {
      "consolidate": "0.9.0",
      "express": "3.1.0",
      "multipart-parser": "0.0.2",
      "mustache": "0.7.2",
      "poplib": "0.1.5",
      "q": "0.9.3",
      "q-io": "1.6.x",
      "request": "2.27.0",
      "string": "^2.2.0",
      "xml2js": "0.2.8"
    }
  </code></pre>
  
  <p>And the question is, why does the promise not receive the full error, I'm sending at <code>deferred.reject(...</code> and what have I to change so that it will work?</p>