Mahahari
Mahahari

Reputation: 1011

how to pass the error messages from back end(sails.js) to front end

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.

Upvotes: 0

Views: 1070

Answers (1)

majidarif
majidarif

Reputation: 20105

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') %>

Upvotes: 4

Related Questions