title: Handling Axios error in React
body: <p>I have a React component that calls a function <code>getAllPeople</code>:</p>
  
  <pre><code>componentDidMount() {
     getAllPeople().then(response =&gt; {
        this.setState(() =&gt; ({ people: response.data }));
      });
    } 
  </code></pre>
  
  <p><code>getAllPeople</code> is in my <code>api</code> module:</p>
  
  <pre><code>export function getAllPeople() {
    return axios
      .get("/api/getAllPeople")
      .then(response =&gt; {
        return response.data;
      })
      .catch(error =&gt; {
        return error;
      });
  }
  </code></pre>
  
  <p>I think this is a very basic question, but assuming I want to handle the error in my root component (in my <code>componentDidMount</code> method), not in the <code>api</code> function, how does this root component know whether or not I the <code>axios</code> call returns an error? I.e. what is the best way to handle errors coming from an <code>axios</code> promise?</p>