Axios - 未处理的拒绝(TypeError):无法读取未定义的 属性 'data'

Axios - Unhandled Rejection (TypeError): Cannot read property 'data' of undefined

我试图自己找出问题所在,但一直很痛苦地想找出答案。我正在使用 axios 并且不知道是什么导致了这个问题。 (我是 ReactJS 的新手)下面我发布了一个屏幕截图,如果它可以让您更容易地确定问题。 enter image description here

export const actFetchMealsRequest = () => {
    return (dispatch) => {
        return callApi('/Product', 'GET', null).then(res => {
            dispatch(GetAllMeal(res.data));
        });
    }
}

/*GET_ALL_MEAL*/
export function GetAllMeal(payload){
    return{
        type:'GET_ALL_MEAL',
        payload
    }
}

我已经按照@Shyam 的建议解决了我的 callApi 中的问题, 这是我之前的代码:

import axios from 'axios';
let API_URL = 'https://5adc8779b80f490014fb883a.mockapi.io';
   export default function callApi(endpoint, method = 'GET', body) {
       return axios({
           method,
           url: `${API_URL}/${endpoint}`,
           data: body
       }).catch(err => {
           console.log(err);
       });
}

这是更新后的代码:

import axios from 'axios';
let API_URL = 'https://5adc8779b80f490014fb883a.mockapi.io';
   export default async function callApi(endpoint, method = 'GET', body) {
       try {
           return axios({
               method,
               url: `${API_URL}/${endpoint}`,
               data: body
           });
       } catch (err) {
           console.log(err);
       }
}

我刚转换成异步函数。