簡體   English   中英

取消請求時在Axios攔截器中獲取請求參數

[英]Get request params in Axios interceptor when the request is cancelled

我有一個攔截器:

axios.interceptors.response.use(doSomething, error => handleError(error));

我可以訪問err.config中有關“正常”錯誤的請求的所有信息

const handleError = err => {
   if(err.config) {
      // use values from err.config
   }
}

但是, Cancel錯誤不包含它。 它只包含message

當請求被取消時,是否可以訪問攔截器中的請求參數?

如果您在處理cancel事件時特別需要某些東西 - 您需要在取消請求的地方提供該信息:

const token = CancelToken.source()
const request = axios.get('/url', { cancelToken: token }).then(....);
token.cancel(
... put here the information that will be available as the `err.message` parameter in the `cancel` interceptor
);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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