title: fetch API : Only redirect if there is no error in POST form
body: <p>I would like to do the following:</p>
  
  <p>POST form via fetch then</p>
  
  <p>If the response is an error message (res.json): stay on same page and <code>alert(json.errorMsg)</code></p>
  
  <p>If the response is a redirect to another page (res.redirect): redirect to new page</p>
  
  <p>The problem is</p>
  
  <p>1) If I use <code>event.preventdefault()</code>, my page does not redirect</p>
  
  <p>2) If I don't use <code>event.preventdefault()</code>, my page always redirect (to a json if there is an error)</p>
  
  <p>Here is summary of my code :</p>
  
  <pre><code>// Client side
  form.addEventListener("submit", () =&gt; {
    fetch(url, fetchData)
      .then((res) =&gt; res.json()) // Transform the data into json
      .then(function (data) {
        alert(data); // Let the user know there was an error in Captcha or provided info
      })
  });
  
  // Server side
  app.post('/', (req, res) =&gt; {
    if (err) {
      console.error(err)
      return res.json({ "success": false, "msg": err })
    }
    return res.redirect("/confirmation_page");
  });
  </code></pre>