[Fixed] NodeJs Express send 403 and render

Issue

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.

Solution

http://expressjs.com/en/api.html#res.status

res.status(403);
res.render();

Or in one line

res.status(403).render();

Leave a Reply

(*) Required, Your email will not be published