Reputation: 20977
I have nginx set to limit file upload size to 2MB and have express set to permit this same size:
nginx:
server {
client_max_body_size 2M;
}
express:
app.use(express.limit('2mb'));
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.
The HTML is what you would expect to see output on the screen for nginx:
<html>
<head><title>413 Request Entity Too Large</title></head>
<body bgcolor="white">
<center><h1>413 Request Entity Too Large</h1></center>
<hr><center>nginx/1.4.4</center>
</body>
</html>
Why is this? How can I make sure that I am only returning an error object and not this much less useful string?
The callback that sends the response is:
callbacks.uploadFailure = function(err){
res.send(413, err);
};
and I have also tried returning json:
callbacks.uploadFailure = function(err){
res.json(413, err);
};
Before I could do something like:
if(err.error.status === 413) {$scope.errmsg = 'File upload too large.'}
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.
Any suggestions or explanations as to why I am not getting an error object to work with?
Upvotes: 0
Views: 500
Reputation: 26690
I suspect the problem is that Nginx is picking up the error before your Express code and that's why you see Nginx error page rather than your Express response.
Try making the value in nginx a bit higher (say 3M) and restart the server again.
Upvotes: 1