javascript - How can I stop node.js 422 (unprocessable entity) redirects showing an intermediary page -
when this:
app.post('/account', function(req, res){ // attempt validate input , insert user db signupuser(req.body, function(success){ if(success){ // validation , sign process successful - send account page res.redirect(302, '/account'); }else{ // validation or else failed - redirect register page // , ask them try again res.redirect(422, '/register'); } }; }) the 302 redirect works fine, 422 redirect sends user page reads

how stop doing this? don't want display page requires user click on link it's going, want go there. can use 302 code response instead, 422 more accurate description of what's going on.
any ideas? lot
its status code beginning 3 makes browser redirect (wikipedia), naturally can't have both http-redirection , 422 status code. have choices here:
- return 3xx status
- return 422 status , make no redirection
- return status , use javascript or meta tag perform redirection
i'd recommend option 2:
- if you're building api don't want http-redirection info went wrong
- if you're building web application it's common practice redirect upon success , leave form errors filled when went wrong (sorry no source on that, maybe can help?)
method called redirect convenience setting status 302 (although can override in example) , location header. should disallowed use status other 3xx avoid confusion such yours.
Comments
Post a Comment