Redux-sagas 无法识别后端.js文件中的功能



我有以下冗余sagas:

import { all, call, fork, put, takeEvery } from "redux-saga/effects";
import { catalogs } from 'backend/Catalogs';
import {
ON_FETCH_CATALOGS,
ON_CRUD_POPULATE_LIST,
ON_CRUD_FETCH_NEXT_PAGE,
ON_CRUD_FETCH_PREVIOUS_PAGE,
ON_CRUD_FETCH_PAGE,
ON_CRUD_CREATE,
ON_CRUD_DELETE,
ON_CRUD_REFRESH_PAGE,
ON_CATALOG_POPULATE_OPTIONS,
ON_CRUD_UPDATE,
ON_CRUD_FETCH_LIST,
ON_CRUD_FETCH_RECORD,
GET_TAGS,
ON_FETCH_AUTOMATS,
} from "constants/ActionTypes";
import {
fetchCatalogsSuccess,
showCatalogsMessage,
crudPopulateListSuccess,
crudFetchNextPageSuccess,
crudFetchPreviousPageSuccess,
crudFetchPageSuccess,
crudRefreshPage,
crudRefreshPageSuccess,
catalogPopulateOptionsSuccess,
crudFetchListSuccess,
crudFetchRecordSuccess,
ListTagsSuccess,
fetchAutomatsSuccess,
} from 'actions/Catalogs';
import { ALERT_ERROR ,ALERT_SUCCESS } from 'attractora/AttrAlert';

...

/// fetchAutomats
const fetchAutomatsRequest = async () => {
return await catalogs.fetchAutomats()
.then (automats => automats)
.catch (error => error)
}
function* fetchAutomatsFromRequest ({payload}) {
try {
const automats = yield call(fetchAutomatsRequest);
if (automats.message) {
yield put(showCatalogsMessage(ALERT_ERROR, automats.message));
} else {
yield put(fetchAutomatsSuccess(automats));
}
} catch (error) {
yield put(showCatalogsMessage(ALERT_ERROR, error));
}
}
export function* fetchAutomats() {
yield takeEvery(ON_FETCH_AUTOMATS, fetchAutomatsFromRequest);
}
/// rootSaga
export default function* rootSaga() {
yield all([
fork(fetchCatalogsList),
fork(crudPopulateList),
fork(crudFetchNextPage),
fork(crudFetchPreviousPage),
fork(crudFetchPage),
fork(crudCreateRecord),
fork(crudUpdateRecord),
fork(crudDeleteRecord),
fork(crudSagaRefreshPage),
fork(catalogPopulateOptions),
fork(crudFetchList),
fork(crudFetchRecord),
fork(crudPopulateListTags),
fork(fetchAutomats),
]);
}

这个backend.js文件:

export const fetchAutomats = () => {
var requestString = backendServer + 'api/general/automats_for_form/'
axios.get(requestString, getAuthHeader())
.then((Response) => {
return { automats: Response.data, message: null };
})
.catch((Error) => {
return getErrorMessage(Error);
})
}
export const catalogs = {
getCatalogs: getCatalogs,
populateList: populateList,
fetchNextPage: fetchNextPage,
fetchPreviousPage: fetchPreviousPage,
fetchPage: fetchPage,
createRecord: createRecord,
deleteRecord: deleteRecord,
refreshPage: refreshPage,
getList: getList,
updateRecord: updateRecord,
fetchList: fetchList,
fetchRecord: fetchRecord,
populateListTags: populateListTags,
fetchAutomats: fetchAutomats,
searchRepositoryByName,
};

由于某种原因,线路return await catalogs.fetchAutomats()上升以下错误:TypeError: Cannot read property 'then' of undefined at fetchAutomatsRequest

我找不到我的错误在哪里。

问题在fetchAutomats方法中,您需要从方法返回promise:

export const fetchAutomats = () => {
var requestString = backendServer + 'api/general/automats_for_form/'
return axios.get(requestString, getAuthHeader())
.then((Response) => {
return { automats: Response.data, message: null };
})
.catch((Error) => {
return getErrorMessage(Error);
})
}

最新更新