title: Handling nginx errors in node/express
body: <p>I have nginx set to limit file upload size to 2MB and have express set to permit this same size:</p>
  
  <p>nginx: </p>
  
  <pre><code>server {
      client_max_body_size 2M;
  }
  </code></pre>
  
  <p>express:</p>
  
  <pre><code>app.use(express.limit('2mb'));
  </code></pre>
  
  <p>In my file upload handler I am logging the errors I get and at one point I was getting an object back that gave me the status code and more useful info. After restarting the server I suddenly stopped getting that error object and now get a string of HTML in its place.</p>
  
  <p>The HTML is what you would expect to see output on the screen for nginx:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;&lt;title&gt;413 Request Entity Too Large&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;413 Request Entity Too Large&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx/1.4.4&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Why is this? How can I make sure that I am only returning an error object and not this much less useful string?</p>
  
  <p>The callback that sends the response is:</p>
  
  <pre><code>callbacks.uploadFailure = function(err){
      res.send(413, err);
  };
  </code></pre>
  
  <p>and I have also tried returning json:</p>
  
  <pre><code>callbacks.uploadFailure = function(err){
      res.json(413, err);
  };
  </code></pre>
  
  <p>Before I could do something like:</p>
  
  <pre><code>if(err.error.status === 413) {$scope.errmsg = 'File upload too large.'}
  </code></pre>
  
  <p>but now I cannot do this as err consists solely of the above listed html string and I would need to parse this string to determine what the error is. Obviously I don't want to be doing that.</p>
  
  <p>Any suggestions or explanations as to why I am not getting an error object to work with?</p>