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