title: How to handle response .json and .text using fetch?
body: <p>I'm fetching an API that returns a json but when it has an error, it returns only a text (In node with express, results are returned with <code>.json({})</code> and errors with <code>.send('string')</code>), but <strong>I can't modify the API</strong>.</p>
  <p>So I'm trying to make something that reads the json, but if it's an text, it will go in <code>.catch</code> where the error is the text.</p>
  <p>Here is what I have tried but with no success:</p>
  <pre><code>fetch(apiUrl)
      .then(res =&gt; {
          try {
              let json = res.json()
              return json
          } catch (error) {
              return new Promise((resolve, reject) =&gt; reject(res.text()))
          }
      })
      .then(res =&gt; {
          // get result from res.json() **res == res.json**
      })
      .catch(error =&gt; {
          // get result from res.text() **res == res.text**
      })
  </code></pre>
  <p>How can I achieve this? How to get <code>res.json()</code> in the next <code>.then()</code> but if it fails, get <code>res.text()</code> in the <code>.catch</code>?</p>
  <p><strong>Edit</strong>: I want to get the <code>.text</code> in <code>.catch</code>. I don't know why, but throwing <code>res.text()</code> doesn't work.</p>