Question

If i have to pass any message/error to front end , in sails.js.

Either we can use one of the following below.

  1. res.view({error : error}) 
  2. res.view("/otherpageurl", {error : error})
  3. res.redirect("/otherpageurl?error="+error)

In some cases , If iam in page A , if any error occurs , i just want to redirect to another page with the error message passed to frontend.whereas in some cases , i just want to show the error in same page.

Is there any other possiblity of passing error messages to frontend?

Please help. Thanks a lot.

Was it helpful?

Solution

Technically you can use the flash middleware for this...

So you would do it like:

req.flash('error', 'Error Message!')
res.redirect('/otherpageurl');

Then on your view:

<%- req.flash('error') %>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top