I'm trying to find a way to handle both 404 and 405 status code in my Express application, but handling them separatedely.
e.g.: I have a router like the following:
// Add routes for every path we define here.
server.use('/', require('./indexRoutes'))
server.use('/account', require('./accountRoutes'))
// Handling route errors.
server.all('*', (request, response) =>
response.status(404).send('Invalid route (not found).')
)
However, either invalid routes or invalid HTTP verbs are being treated by the server.all
method. Is there a way to treat them separatedely, in order to send different status, content and everything for each scenario?
Thank y'all!