簡體   English   中英

Axios - 攔截器:阻止原始調用者進一步處理

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM