title: Why is my JavaScript Fetch not able to get the error object
body: <p>I have a JavaScript that makes a Fetch post call to the backend of the site. If the post-call goes well, the Fetch is able to handle the response. If something goes wrong in the post-call, the Fetch is not able to handle the error. </p>
  
  <p>This are my codes:</p>
  
  <pre><code>async function startFetch(url, data_post){ 
    return fetch(url, {
      method: 'POST', // or 'PUT'
      body: JSON.stringify(data_post), // data can be `string` or {object}!
      headers:{  
        'Content-Type': 'application/json'
      }
    })
    .then(response =&gt; response.json());
  }
  
  async function makeFetch(arrRows){
    let url = 'somebackendpost';
  
    for(const item of ArrRows){
      let data_post = {};
      data.name = item;
  
      await startFetch(url, data_post)
      .then(data =&gt; {
        //when the fetch is okay, this part is executed
        console.log(data);
        //do other things like output to html
        $('#result').append('&lt;p&gt;' + data.result + '&lt;/p&gt;');
      })
      .catch(error ={
        //a timeout 504 error occured, but this part seemed not to execute
        console.log('error is', error);
        //the code below is wrong (but has since been removed then)
        //Is this the reason why the catch error part did not work?
        //Since the code below has been removed, can I expect the catch error to now work?
        $('#result').append('&lt;p&gt;' + data.result + '&lt;/p&gt;');
      });
  
    }
  }
  
  function startProcess(){
    //called by button click
    let arrRows = ["Row1", "Row2", "Row3"];
    makeFetch(arrRows);
  }
  </code></pre>
  
  <p>At the time, the code was executed, there was a server issue. The browser console displayed a Gateway timeout error 504. Here is the console logs:</p>
  
  <pre><code>Fetch failed loading: POST "mysite/somebackendpost"
  POST mysite/somebackendpost 504 (GATEWAY TIMEOUT)
  error is SyntaxError: Unexpected end of JSON input
   at fetch.then.response
  Uncaught (in promise) ReferenceError: X is not defined
    at startFetch.then.catch.error
  </code></pre>