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
}
Как я могу прервать обработку запроса http после того, как http:
Я могу написать
if (some_error) { http_send_error(req, res); return }
или
if (some_error) http_send_error(req, res)
else {
//process without error
}
но выглядит более многословно и нечитаемо. Как я могу сломать httpHandler после ошибки?