title: What is causing an Unhandled Promise Rejection: undefined is not an object (evalutating '_context.t0.response.data')?
body: <p>I keep getting an Unhandled Promise Rejection: TypeError: undefined is not an object (evaluating '_context.t0.response.data'). After doing some digging, it seems like my error is coming from this part of my code. It's the authUser function specifically that seems to be causing the problem</p>
  
  <pre><code>import { addError, removeError } from './error';
  import { SET_CURRENT_USER } from '../actionTypes';
  import api from '../../services/api';
  
  export const setCurrentUser = user =&gt; ({
      type: SET_CURRENT_USER,
      user
  });
  
  export const setToken = token =&gt; {
      api.setToken(token);
  };
  
  export const authUser = (path, data) =&gt;
  {
      return async dispatch =&gt; {
          try {
              const {token, ...user} = await api.call('post', `auth/${path}`, data);
              AsyncStorage.setItem('jwtToken', token);
              api.setToken(token);
              dispatch(setCurrentUser(user));
              dispatch(removeError());
          } catch (err) {
              const error = err.response.data;
              dispatch(addError(error.message));
          }
      }
  };
  </code></pre>
  
  <p>actionTypes.js</p>
  
  <pre><code>export const SET_CURRENT_USER = 'SET_CURRENT_USER'
  </code></pre>
  
  <p>api.js</p>
  
  <pre><code>import axios from 'axios';
  
  const host = 'http://localhost:4000/api';
  
  export const setToken = token =&gt; {
      if (token) {
          axios.defaults.headers.common['Authorization'] = `Bearer ${token}`;
      } else {
          delete axios.defaults.headers.common['Authorization'];
      }
  };
  
  export const call = async (method, path, data) =&gt; {
      const response = await axios[method](`${host}/${path}`, data);
      return response.data;
  };
  
  export default { setToken, call };
  
  </code></pre>
  
  <p>error.js</p>
  
  <pre><code>import {ADD_ERROR, REMOVE_ERROR} from '../actionTypes';
  
  export const addError = error =&gt; ({
      type: ADD_ERROR,
      error
  });
  
  export const removeError = () =&gt; ({
      type: REMOVE_ERROR
  });
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Possible Unhandled Promise Rejection (id: 4):
  TypeError: undefined is not an object (evaluating '_context.t0.response.data')
  _callee$@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:107239:43
  tryCatch@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:26927:23
  invoke@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:27103:32
  tryCatch@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:26927:23
  invoke@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:27003:30
  http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:27015:21
  tryCallOne@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:28865:16
  http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:28966:27
  _callTimer@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:32405:17
  _callImmediatesPass@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:32441:19
  callImmediates@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:32659:33
  callImmediates@[native code]
  __callImmediates@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:2719:35
  http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:2505:34
  __guard@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:2702:15
  flushedQueue@http://localhost:8081/index.bundle?platform=android&amp;dev=true&amp;minify=false:2504:21
  flushedQueue@[native code]
  callFunctionReturnFlushedQueue@[native code]
  </code></pre>
  
  <p>Also if it helps, I followed the localhost link and the function that is breaking there, tho I did not write this and cannot change it.</p>
  
  <pre><code>
    var authUser = function authUser(path, data) {
      return function _callee(dispatch) {
        var _await$api$call, token, user, error;
  
        return _regenerator.default.async(function _callee$(_context) {
          while (1) {
            switch (_context.prev = _context.next) {
              case 0:
                _context.prev = 0;
                _context.next = 3;
                return _regenerator.default.awrap(_api.default.call('post', "auth/" + path, data));
  
              case 3:
                _await$api$call = _context.sent;
                token = _await$api$call.token;
                user = (0, _objectWithoutProperties2.default)(_await$api$call, ["token"]);
                AsyncStorage.setItem('jwtToken', token);
  
                _api.default.setToken(token);
  
                dispatch(setCurrentUser(user));
                dispatch((0, _error.removeError)());
                _context.next = 16;
                break;
  
              case 12:
                _context.prev = 12;
                _context.t0 = _context["catch"](0);
                error = _context.t0.response.data;
                dispatch((0, _error.addError)(error.message));
  
              case 16:
              case "end":
                return _context.stop();
            }
          }
        }, null, null, [[0, 12]], Promise);
      };
    };
  </code></pre>