RangeError: Invalid status code: 0 in Express App - Session issue?
<p>I have this random error on a express app:</p>

<pre><code>_http_server.js:192
    throw new RangeError(`Invalid status code: ${statusCode}`);
    ^

RangeError: Invalid status code: 0
    at ServerResponse.writeHead (_http_server.js:192:11)
    at ServerResponse.writeHead (/project-folder/node_modules/express-session/node_modules/on-headers/index.js:55:19)
    at ServerResponse._implicitHeader (_http_server.js:157:8)
    at ServerResponse.OutgoingMessage.end (_http_outgoing.js:573:10)
    at writeend (/project-folder/node_modules/express-session/index.js:257:22)
    at Immediate.onsave [as _onImmediate] (/project-folder/node_modules/express-session/index.js:325:11)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
</code></pre>

<p>I tried to fix it by doing something like this with no luck:</p>

<pre><code>app.use(function(req, res, next) {
    req.on("end", function() {
        if (res.statusCode &lt; 100 &amp;&amp; res.statusCode &gt;= 600) {
          res.status(500);          
        }
    });
    next();
});
</code></pre>

<p>I have no idea where to find the error or at least put a try catch, the error is random and the trace is not very explicit.</p>

<p>Any help is welcome, thanks! </p>