How can I send a error 403 and render a page with 'you have no rights to visited this page' message?
I have now this:
res.send(403,"You do not have rights to visit this page");
but I want to render a HTML page instead a basic text
res.render('no-rights', {title: 'You have no rights to visit this page', text: 'You are not allowed to visited this page. Maybe you are not logged in?'});
with a 403 status.
http://expressjs.com/en/api.html#res.status
res.status(403);
res.render();
Or in one line
res.status(403).render();
As you can see in the error handling page of Express you can set the status first and then render the page.
res.status(500);
res.render('error', { error: err });
similarly I would create a page that could inform the user about the 4xx (client error) and 5xx (server error) errors in a similar way by passing the status code and the title as parameters.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With