title: how to get response data in fetch if status code is 400 react js
body: <p>I am fetching data from a api end point.
  It takes username,email,password,firstname,lastname and register it to database.
  Now if some error occurs like email already used then it gives a 400 status code and sends this</p>
  <pre><code>{
      &quot;err&quot;: &quot;A user with the given email is already registered&quot;
  }
  </code></pre>
  <p>so I want to use this api endpoint.
  In react js I am doing this.</p>
  <pre><code>const printError=(err)=&gt;{
      if((typeof(err)=='string'))
          return err
      else if(err.err!=undefined)
          return err.err
      else if(err.message!=undefined)
          return err.message
      else
          return 'Some error occured.Try Again later.'
  }
  fetch(BaseUrl+'users/signup',{
          method:'post',
          credentials:'include',
          body:JSON.stringify(user),
          headers:{
              'content-type':'application/json'
          }
      })
      .then(response=&gt;{
          console.log(response)
          if(response.ok)
              return response.json()
          else{
              throw new Error(response)
          }
      })
      .then(response=&gt;{
          alert(response.status)
      })
      .catch(error =&gt;  { console.log('Registration error');console.log(error); alert('Registration Failed\nError: '+printError(error)); });
  
  </code></pre>
  <p>Please tell me how to get this err object when email is already taken.</p>