title: Axios error handling the err.response object
body: <p>I have an React/Redux action creator which makes a post request on creation of a new user's account.</p>
  <p>When I test the server validation I am expecting the <code>err.response</code> object inside the catch to be defined and return the validation error message. However, the <code>err.response</code> and <code>err.request</code> objects are not defined and I am getting the generic &quot;An internal error occurred&quot; when the user should be seeing the validation error instead.</p>
  <p>I have followed the setup they recommended at <a href="https://github.com/axios/axios#handling-errors" rel="nofollow noreferrer">https://github.com/axios/axios#handling-errors</a>, however I've found no luck. Any idea?</p>
  <pre><code>import { REGISTER_SUCCESS, REGISTER_FAILED, RegisterReq, TokenRes } from &quot;./types&quot;;
  import { returnErrors } from &quot;../errors/actions&quot;;
  import { Config } from &quot;../../utils/tokenConfig&quot;;
  import axios, { AxiosResponse, AxiosError } from &quot;axios&quot;;
  
  export const registerUser = (user: RegisterReq) =&gt; (dispatch:Function):void =&gt; {
      const config: Config = {
          headers: {
              &quot;Content-Type&quot;: &quot;application/json&quot;
          },
          withCredentials: false
      };
  
      axios.post&lt;TokenRes&gt;(&quot;/v1/users&quot;, user, config)
          .then((res: AxiosResponse&lt;TokenRes&gt;):void =&gt; dispatch({
              type: REGISTER_SUCCESS,
              payload: res.data
          }))
          .catch((err: AxiosError):void =&gt; {
              if(err.response) dispatch(returnErrors(err.response.data, err.response.status, REGISTER_FAILED));
              
              else if(err.request) dispatch(returnErrors(err.request.data, err.request.status, REGISTER_FAILED));
           
              dispatch(returnErrors(&quot;An internal error occurred&quot;, 500, REGISTER_FAILED));
          });
  };
  </code></pre>