Skip to content Skip to sidebar Skip to footer

Rangeerror: Invalid Status Code: 0

I am having an issue where I am getting the following error code when attempting a POST request on this application (bearing in mind I am a beginner node.js/js programmer): Error:

Solution 1:

I had a similar error message just now and managed to solve the problem by changing:

res.status(statusCode);

to:

if (statusCode >= 100 && statusCode < 600)
  res.status(statusCode);
else
  res.status(500);

or just:

res.status(statusCode >= 100 && statusCode < 600 ? err.code : 500);

I.e. make sure you aren't trying to set an invalid HTTP status code somewhere.

It's likely this is the issue but it looks like you've accidentally duplicated the app.js code instead of pasting the edit.js code in the question.

Solution 2:

This case also happen when we have validation error on form save and we are using res.redirect instead of res.render method

for example-

Please Use

res.render('users/add', {
    countries: countries
});

instead of (it's wrong statement for node)

res.redirect('/users/add', {
    countries: countries
});

Solution 3:

for me the issue was that i had not created my upload directory and it returns me the error. may be you should consider to create your ./upload directory first, because of permission issues on linux.

Solution 4:

I had the same problem which I solved by using:

res.send('0')

instead of

res.send(0)

Post a Comment for "Rangeerror: Invalid Status Code: 0"