Here is the code in nodejs.

app.use(function(req,res){ res.type('text/plain'); res.status(404); res.send('404 - Не найдено'); }); app.use(function(err, req, res, next){ console.error(err.stack); res.type('text/plain'); res.status(500); res.send('500 - Ошибка сервера'); }); 
  • This is the express.js code. But what is the question I did not understand - Alexey Ten
  • There are two functions, they return two errors. How a 404 error can be triggered and how a 500 error can be caused if the functions are simply written in a row. - xverizex 1:49 pm
  • You should start reading from the express.js documentation, in particular, how error handling is arranged there - Alexey Ten 1:59 pm
  • And found. Express can distinguish handlers 404 and 500 by the number of arguments accepted by their callback functions. - xverizex

1 answer 1

Express can distinguish handlers 404 and 500 by the number of arguments accepted by their callback functions.