var http = require('http'); http.createServer(httpHandler).listen(80);
function httpHandler(req, res)
{
let some_error = 'shit happened'
if (some_error) http_send_error(req, res)
console.log('we should not be here if http error sent')
costly_processing()
}
function http_send_error(req, res)
{
res.writeheader(500, 'Content-type: text/plain')
res.end("something wrong")
die() // I have to break this thread and stop handling this request
}
How can I break http request handling after this error message was sent by http?
I can write
if (some_error) { http_send_error(req, res); return }
or
if (some_error) http_send_error(req, res)
else {
//process without error
}
but it looks more verbose and unreadable. How can I break httpHandler after error?
if (some_error) return http_send_error(req, res)