title: node.js' express middleware does not return error on nodester
body: <p>My node app uses the express framework. I developed a middleware to check parameters but when an error is sent by the middleware it is not sent back in the response.
  I only have this problem on nodester, on localhost it works as expected.</p>
  
  <p>Here is an example of the controller action:</p>
  
  <pre><code>/*
   * Create a new user
   *
   */
  app.post('/user/create', md.checkParams(["nickname", "email", "password"]), function(req, res){
    var email    = req.query.email;
    var nickname = req.query.nickname;
    var password = req.query.password;
    jsonObj = { "nickname" : nickname, "email" : email, "password" : password };
  
    // Save user in DB
    db.hmset("user:" +nickname, jsonObj, function(err1){
      if(!err1) {
        db.sadd("users","user:" + nickname, function(err2){
          if(err2){
            jsonObj = {"error" : "database error", "message" : "error adding object to set" };
          }
          h.respond(res, jsonObj);
        });
      } else {
        jsonObj = {"error" : "database error", "message" : "error creating hash for object" };
        h.respond(res, jsonObj);
      }
    });
  });
  </code></pre>
  
  <p>The checkParams middleware is:</p>
  
  <pre><code>function checkParams(arr){
    return function(req, res, next) {
      // Make sure each param listed in arr is present in req.query
      var missing_params = [];
      for(var i=0;i&lt;arr.length;i++){
        if(! eval("req.query." + arr[i])){
          missing_params.push(arr[i]);
        }
      }
      if(missing_params.length == 0){
        next();
      } else {
        next(JSON.stringify({ "error" : "query error", "message" : "Parameter(s) missing: " + missing_params.join(",") }));
      } 
    }
  }
  </code></pre>
  
  <p>For instance, if I use a</p>
  
  <pre><code>curl -XPOST 'http://HOST/users/create'
  </code></pre>
  
  <p>on localhost I get: </p>
  
  <p>{"error":"query error","message":"Parameter(s) missing: nickname,email,password"}</p>
  
  <p>on NODESTER I only got:</p>
  
  <pre><code>Internal Server Error 
  </code></pre>
  
  <p>({"error":"query error","message":"Parameter(s) missing: nickname,email,password"} appears in the app log but not in the response)</p>
  
  <p>Any idea what could be wrong ?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>I found a workaround by issuing the following in the middleware when an error is supposed to be thrown:</p>
  
  <pre><code>res.writeHead(200, {'content-type': 'application/json'});
  res.write("my error message");
  res.end();
  </code></pre>
  
  <p>instead of </p>
  
  <pre><code>next("my error message);
  </code></pre>
  
  <p>it's working this way even if I'm not 100% sure this is best solution.</p>