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


422 node response page


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:

  1. return 3xx status
  2. return 422 status , make no redirection
  3. return status , use javascript or meta tag perform redirection

i'd recommend option 2:

  1. if you're building api don't want http-redirection info went wrong
  2. 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

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -