如何根据 api 响应状态拦截 redux-saga?
How to intercept redux-saga depending on api response status?
在我的 react-native 项目中,我想在从 api 请求获得响应并导航到屏幕后全局处理 204(无内容错误)响应。在saga中拦截应该怎么做?
您可以将 api 调用包装在下面的生成器函数中,该函数将从您的响应中拦截 204 并导航到所需的屏幕
export function* callApi(apiCall) {
const response = yield apiCall;
if (!isNoContent(response)) {
return response;
}
//navigate to screen
return response;
}
function isNoContent(resp) {
return (
resp.status === 204
);
}
const apiCall = call(apiRequestService, payload);
const json = yield call(callApi, apiCall);
在我的 react-native 项目中,我想在从 api 请求获得响应并导航到屏幕后全局处理 204(无内容错误)响应。在saga中拦截应该怎么做?
您可以将 api 调用包装在下面的生成器函数中,该函数将从您的响应中拦截 204 并导航到所需的屏幕
export function* callApi(apiCall) {
const response = yield apiCall;
if (!isNoContent(response)) {
return response;
}
//navigate to screen
return response;
}
function isNoContent(resp) {
return (
resp.status === 204
);
}
const apiCall = call(apiRequestService, payload);
const json = yield call(callApi, apiCall);