【发布时间】:2019-08-26 03:25:03
【问题描述】:
我正在尝试处理 HTTP 重定向状态代码(例如,会话超时时的 302 重定向),但我不知道是否有使用 redux-observable 处理特定响应代码的通用方法?我现在遇到的问题是浏览器遵循 302 响应中指定的位置,我只能点击登录页面的后续 200 响应。我现在有一些技巧,我在响应 URL 中检测到“登录”一词并使用 window.location 对象重定向到登录页面。我必须在每部史诗中都这样做。
这是我得到的:
export const getData = (action$) => {
return action$.pipe(
ofType(GET_DATA_REQUEST),
mergeMap(action => {
return ajax(options).pipe(
map((response) => response.originalEvent.currentTarget.responseURL.endsWith('login') ? window.location.href = 'login' : getDataSuccess(response.response)),
catchError(error => of(getDataFailure(error)))
);
}),
catchError(error => of(getDataFailure(error)))
);
};
有没有人知道任何更好的方法来处理这个问题,而我不必为所有新的史诗重复它?
【问题讨论】:
标签: reactjs react-redux redux-observable