title: Warn : Possible Unhandled Promise Rejection (id: 0)
body: <p>I am building ecommerce app using react-native I just encountered an error which i don't know what it mean</p>
  <p>Error is &quot;Possible Unhandled Promise Rejection (id: 0):
  TypeError: undefined is not an object (evaluating 'err.response.data')&quot;</p>
  <p>I have used &quot;err.response.data&quot; in  2-3 file but i have mentioned code of one file</p>
  <pre><code>import AsyncStorage from '@react-native-community/async-storage';
  import axios from 'axios';
  import {returnErrors} from './errorActions';
  import {ADD_TO_CART, CHECK_OUT} from './types';
  import {
    AllDispatchProp,
    API_URI,
    CLEAR_ERRORS,
    DELETE_PRODUCT,
    LOADED_PRODUCTS,
    LOADING_PRODUCTS,
    SENT_PRODUCT,
  } from './types';
  
  export const addProduct = ({
    title,
    price,
    imageUrl,
    desc,
  }: {
    title: string;
    price: string;
    imageUrl: string;
    desc: string;
  }) =&gt; async (dispatch: AllDispatchProp, getState: any) =&gt; {
    const auth = getState().auth;
    const data = JSON.stringify({title, price, imageUrl, desc, user: auth.user});
    const token = AsyncStorage.getItem('@user_token');
  
    //* Store a product
    axios({
      method: 'POST',
      url: `${API_URI}/api/product`,
      data,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: CLEAR_ERRORS, payload: null});
        dispatch({type: SENT_PRODUCT, payload: res.data._doc});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(
            err.response.data,
            err.response.status,
            'PRODUCT_POST_FAIL',
          ),
        );
      });
  };
  
  //* Load Amazon Products *//
  export const loadProducts = () =&gt; async (dispatch: AllDispatchProp) =&gt; {
    dispatch({type: LOADING_PRODUCTS, payload: null});
    const token = await AsyncStorage.getItem('@user_token');
  
    //* Load products from url *//
    axios({
      method: 'GET',
      url: `${API_URI}/api/product`,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: LOADED_PRODUCTS, payload: res.data});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(
            err.response.data,
            err.response.status,
            'LOAD_PRODUCT_FAIL',
          ),
        );
      });
  };
  
  export const deleteProduct = (_id: string) =&gt; async (
    dispatch: AllDispatchProp,
  ) =&gt; {
    const data = JSON.stringify({_id});
    const token = await AsyncStorage.getItem('@user_token');
  
    axios({
      method: 'DELETE',
      url: `${API_URI}/api/product`,
      data,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: DELETE_PRODUCT, payload: res.data._id});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(
            err.response.data,
            err.response.status,
            'DELETE_PRODUCT_FAIL',
          ),
        );
      });
  };
  
  //* Amazon add to cart *//
  export const addToCart = (_id: string) =&gt; async (
    dispatch: AllDispatchProp,
    getState: any,
  ) =&gt; {
    const {products, cartProducts} = getState().product;
    const cartProduct = cartProducts.filter((p: any) =&gt; p._id === _id);
    const isInCart = cartProduct.length &gt; 0;
    const data = JSON.stringify({_id});
    const token = await AsyncStorage.getItem('@user_token');
  
    if (!isInCart) {
      axios({
        method: 'PUT',
        url: `${API_URI}/api/product`,
        headers: {
          'content-type': 'application/json',
          'x-app-token': token,
        },
        data,
      })
        .then((res) =&gt; {
          dispatch({type: ADD_TO_CART, payload: res.data});
        })
        .catch((err) =&gt; {
          dispatch(
            returnErrors(
              err.response.data,
              err.response.status,
              'ADD_TO_CART_FAIL',
            ),
          );
        });
    }
  };
  
  export const productCheckOut = () =&gt; async (dispatch: AllDispatchProp) =&gt; {
    const token = await AsyncStorage.getItem('@user_token');
  
    axios({
      method: 'GET',
      url: `${API_URI}/api/product`,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: CHECK_OUT, payload: res.data});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(err.response.data, err.response.status, 'CHECKOUT_FAIL'),
        );
      });
  };
  
  export const clearCart = () =&gt; async (dispatch: AllDispatchProp) =&gt; {
    const token = await AsyncStorage.getItem('@user_token');
    axios({
      method: 'PUT',
      url: `${API_URI}/api/product/clear`,
      headers: {
        'x-app-token': token,
      },
    })
      .then(() =&gt; {
        return loadProducts();
      })
      .catch(() =&gt; {});
  };
  </code></pre>
  <p>I dont from where this error occurred but I really need help in this on</p>
  <p>This is the &quot;returnErrors&quot; file</p>
  <pre><code>import {GET_ERRORS, CLEAR_ERRORS} from './types';
  
  // RETURN ERRORS
  export const returnErrors = (
    msg: string,
    status: string | number,
    id: string | null,
  ) =&gt; {
    return {
      type: GET_ERRORS,
      payload: {msg, status, id},
    };
  };
  
  // CLEAR ERRORS
  export const clearErrors = () =&gt; {
    return {
      type: CLEAR_ERRORS,
    };
  };
  </code></pre>
  <p>After editing;</p>
  <pre><code>import AsyncStorage from '@react-native-community/async-storage';
  import axios from 'axios';
  import {returnErrors} from './dist/errorActions';
  import {ADD_TO_CART, CHECK_OUT} from './dist/types';
  import {
    AllDispatchProp,
    API_URI,
    CLEAR_ERRORS,
    DELETE_PRODUCT,
    LOADED_PRODUCTS,
    LOADING_PRODUCTS,
    SENT_PRODUCT,
  } from './types';
  
  export const addProduct = ({
    title,
    price,
    imageUrl,
    desc,
  }: {
    title: string;
    price: string;
    imageUrl: string;
    desc: string;
  }) =&gt; async (dispatch: AllDispatchProp, getState: any) =&gt; {
    const auth = getState().auth;
    const data = JSON.stringify({title, price, imageUrl, desc, user: auth.user});
    const token = AsyncStorage.getItem('@user_token');
  
    //* Store a product
    axios({
      method: 'POST',
      url: `${API_URI}/api/product`,
      data,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: CLEAR_ERRORS, payload: null});
        dispatch({type: SENT_PRODUCT, payload: res.data._doc});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(
            err.response?.data ?? 'your default msg',
            err.response?.status ?? 'your default status',
            'PRODUCT_POST_FAIL',
          ),
        );
      });
  };
  
  //* Load app Products *//
  export const loadProducts = () =&gt; async (dispatch: AllDispatchProp) =&gt; {
    dispatch({type: LOADING_PRODUCTS, payload: null});
    const token = await AsyncStorage.getItem('@user_token');
  
    //* Load products from url *//
    axios({
      method: 'GET',
      url: `${API_URI}/api/product`,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: LOADED_PRODUCTS, payload: res.data});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(
            err.response.data,
            err.response.status,
            'LOAD_PRODUCT_FAIL',
          ),
        );
      });
  };
  
  export const deleteProduct = (_id: string) =&gt; async (
    dispatch: AllDispatchProp,
  ) =&gt; {
    const data = JSON.stringify({_id});
    const token = await AsyncStorage.getItem('@user_token');
  
    axios({
      method: 'DELETE',
      url: `${API_URI}/api/product`,
      data,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: DELETE_PRODUCT, payload: res.data._id});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(
            err.response.data,
            err.response.status,
            'DELETE_PRODUCT_FAIL',
          ),
        );
      });
  };
  
  //* app add to cart *//
  export const addToCart = (_id: string) =&gt; async (
    dispatch: AllDispatchProp,
    getState: any,
  ) =&gt; {
    const {products, cartProducts} = getState().product;
    const cartProduct = cartProducts.filter((p: any) =&gt; p._id === _id);
    const isInCart = cartProduct.length &gt; 0;
    const data = JSON.stringify({_id});
    const token = await AsyncStorage.getItem('@user_token');
  
    if (!isInCart) {
      axios({
        method: 'PUT',
        url: `${API_URI}/api/product`,
        headers: {
          'content-type': 'application/json',
          'x-app-token': token,
        },
        data,
      })
        .then((res) =&gt; {
          dispatch({type: ADD_TO_CART, payload: res.data});
        })
        .catch((err) =&gt; {
          dispatch(
            returnErrors(
              err.response.data,
              err.response.status,
              'ADD_TO_CART_FAIL',
            ),
          );
        });
    }
  };
  
  export const productCheckOut = () =&gt; async (dispatch: AllDispatchProp) =&gt; {
    const token = await AsyncStorage.getItem('@user_token');
  
    axios({
      method: 'GET',
      url: `${API_URI}/api/product`,
      headers: {
        'content-type': 'application/json',
        'x-app-token': token,
      },
    })
      .then((res) =&gt; {
        dispatch({type: CHECK_OUT, payload: res.data});
      })
      .catch((err) =&gt; {
        dispatch(
          returnErrors(err.response.data, err.response.status, 'CHECKOUT_FAIL'),
        );
      });
  };
  
  export const clearCart = () =&gt; async (dispatch: AllDispatchProp) =&gt; {
    const token = await AsyncStorage.getItem('@user_token');
    axios({
      method: 'PUT',
      url: `${API_URI}/api/product/clear`,
      headers: {
        'x-app-token': token,
      },
    })
      .then(() =&gt; {
        return loadProducts();
      })
      .catch(() =&gt; {});
  };
  </code></pre>
  <p>and returnErrors file
  <strong>Note: <em>when i am editing returnError code i got an error &quot;Unexpected Token&quot; on question mark symbol</em></strong></p>
  <pre><code>import {GET_ERRORS, CLEAR_ERRORS} from './types';
  
  // RETURN ERRORS
  export const returnErrors = (
      msg: string | undefined,
      status: string | number | undefined,
      id: string | null,
    ) =&gt; {
      return {
        type: GET_ERRORS,
        payload: {msg??&quot;your default msg&quot;, status??&quot;your default status&quot;, id},
      };
    };
  
  // CLEAR ERRORS
  export const clearErrors = () =&gt; {
    return {
      type: CLEAR_ERRORS,
    };
  };
  </code></pre>
  <p>One more thing whenever i'm trying to register in app it throw this error only(i hope u understand what i'm trying to say)</p>