0

您好,我想知道我的代码有什么问题:
即使我的 ajax 请求有效,但payload对象始终未定义。

如果我正确理解 sagas,该fetchWord函数应该等待fetchWordRequestpromise 被解决,对吗?

export function* fetchWordSaga(action) {
   try {
      const { payload } = yield call(fetchWordRequest, action.payload);
      if (typeof payload !== "undefined") {
         yield put({
            type: types.FETCH_WORD_SUCCESS,
            payload: digestResponse(payload)
         })
      } else {
         throw new Error("payload is undefined");
      }
   }
   catch(error) {
      yield put({
         type: types.FETCH_WORD_ERROR,
         error: error.message
      })
   }
}

export function fetchWordRequest({word, params}) {
   let { lang, filters } = params;
   let url = `https://.../${lang}/${word}`;
   return axiosConfig.get(url)
       .then(response => {
          return response;
       })
       .catch(error => {
          throw error
       })
}
4

0 回答 0