NodeJs Express sends 403 and does

How can I send a 403 error message and display a page with the message "you are not allowed to visit this page"?

I have the following:

res.send(403,"You do not have rights to visit this page");

but I want to make an HTML page instead of body 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 status of 403.

+4
source share
2 answers

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

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

Or in one line

res.status(403).render();
+6
source

As you can see on the error handling page , you can first set the status and then display the page.

  res.status(500);
  res.render('error', { error: err });

, , 4xx ( ) 5xx ( ) , .

0

Source: https://habr.com/ru/post/1650799/


All Articles