title: React Native / Expo: fetch throws "Network request failed" error on 401 response with formData content type
body: <p>I am creating an expo app that interacts with a Django Rest Framework backend. I use fetch to get and post data to my server, and have JWT authentication set up. Fetch works as I expect it to sending json data to my server.</p>
  
  <p>I am also trying to post some images to my server, and this works as expected until my token expires and the server returns a 401. When this happens on Android, fetch rather than resolving properly and having a response.status of 401, instead throws a <code>TypeError: Network request failed</code>. On iOS it just hangs.</p>
  
  <p>Sample Code:</p>
  
  <pre><code>const formData = new FormData()
  photos.map((photo, index) =&gt;
    formData.append('images', {
      name: `test${index}.jpg`,
      type: 'image/jpeg',
      uri: photo.uri,
    }),
  )
  try {
    const response = await fetch(url, {
      body: formData,
      headers: {
        Authorization: `Bearer ${userToken}`,
      },
      method: 'POST'
    })
  } catch (e) {
    console.log(e)
  }
  </code></pre>
  
  <p>Fetch normally resolves properly when my server returns a 200 or 401, but when I post the image data, 200s resolve successfully but 401s cause fetch to throw a network request failed error. How do I stop this from happening?</p>
  
  <p><strong>Edit</strong>: Further research shows that the line of python code <code>images = request.FILES.getlist('images', [])</code> is crucial to not having this error. If I manually return before this line of code then I get the same issue. My guess is that this has something to do with the multipart upload being interrupted by an error but I am not sure how to handle this in the app.</p>