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

烂漫一生 提交于 2019-12-25 06:38:56

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/23234457/how-to-pass-the-error-messages-from-back-endsails-js-to-front-end

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!