title: Catch 504 (Gateway Timeout) Error in React, JavaScript
body: <p>I have a working API to get items from the server as below. I am using React to use this data. Now, I want to catch all server errors that begins with 5__ and display a message like "No connection with internet" or something like that.</p>
  
  <pre><code> export const GetItems = (operand, searchValue) =&gt; {
        const trimmedValue = searchValue.trim();
        let combinedResults;
        // make 2 API calls to search on both item_name and code;
        // then combine them;
        // there is no API method to do this, that I could find
        return getItemsByName(operand, trimmedValue)
        .then(result =&gt; (
          (combinedResults = [].concat(result))
        ))
        .then(() =&gt; getItemsByCode(operand, trimmedValue))
        .then(result =&gt; (
          (combinedResults = combinedResults.concat(result))
        ));
      };
  </code></pre>
  
  <p>Currently, I need to look at the console to check if there is a problem with connection.</p>
  
  <p><a href="https://i.stack.imgur.com/LL85P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LL85P.png" alt="504 Gateway Timeout Error "></a></p>
  
  <hr>
  
  <p><strong>Updated as @Dane requested</strong></p>
  
  <pre><code>const getItemsByCode = (operand, searchValue) =&gt; (
    FetchToJson(BuildCodeSearchUrl(operand, searchValue))
  );
  </code></pre>
  
  <p>It's just calling a method to build the URL. You can consider that everything is working good, getting the response if there is a connection.</p>