title: Getting custom error message using fetch api when http response status is 400
body: <p>I have Python Flask (v 1.0.0) backend that returns an http response with status 400 and a custom error message</p>
  
  <pre><code>return Response('My custom errror message', 400)
  </code></pre>
  
  <p>In my frontend I have an API call to the backend using Fetch API:</p>
  
  <pre><code>fetch(url, options)
    .then(response =&gt; response.json())
    .then(response =&gt; console.log(response))
    .catch(error =&gt; console.log(error));
  </code></pre>
  
  <p>Since 400 is a <code>BAD REQUEST</code>, <code>fetch</code> goes straight to <code>catch</code> and all I have is <code>TypeError: Failed to fetch</code> message.</p>
  
  <p>How can I get my custom error message in frontend instead of <code>Failed to fetch</code> message? It is visible in the DevTools, so I hope it should be available in <code>fetch</code> somehow?</p>
  
  <p><a href="https://i.stack.imgur.com/KknOK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/KknOK.png" alt="enter image description here"></a><a href="https://i.stack.imgur.com/s7urJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/s7urJ.png" alt="enter image description here"></a></p>