Here's a node. JS function is it works, bad json data is removed in this sense, but it also shines the message that failed. Why?
// document app post ('/ documents.:format?', LoadUser, function (rik, ridge) /////////////// ///////// Added by ADAM / test to see that the input text is valid JSON data data = req.body.d.data; console.log ("////// /// // "+ data") {type = JSON.parse (data); console.log (type);} hold (east) {console.log ("bad json:" + data); req.flash ('no ',' Invalid JSON '); res.redirect (' / document '); return;} var d = new document (req.body.d); d.user_id = req.currentUser.id; d.save (Function ( } {Switch (req.params.format)} {case 'json': res.send (d.toObject ()); break; default: req.flash ('info', 'document created'); res read Hold (code '/ document');}});
There are both error messages and 'bad JSON' logger in block, so they are always at the same time due to block scope.
Comments
Post a Comment