[英]Axios - Interceptors: prevent further handling by original caller
我的 Axios 實例有一個成功的響應攔截器。 在某些情況下,我基本上想阻止進一步執行 .then( .then()
和.catch()
。
axiosExtended.interceptors.response.use(response => successHandler(response), error => errorHandler(error))
function successHandler(response) {
const relativeRequestUrl = response.config.url;
const relativeResponseUrl = trim(response.request.responseURL.replace(response.config.baseURL, ''), '/');
if (relativeRequestUrl !== relativeResponseUrl) {
// dont return anything to original caller. No then. No catch.
router.push(relativeResponseUrl)
}
// get handled by original caller...
}
感謝@felixmosh:
instance.interceptors.response.use((response) => {
if (someCondition(response) {
return new Promise(() => {});
}
return response;
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.