[英]Retry axios request when response is empty
await axios
.post(
executeBatch,
{
headers: {
"Content-Type": "application/json",
"x-access-token": localStorage.getItem("token"),
},
}
)
.then(
(response) =>
this.$store.commit(
"insertOutputFile",
response.data.outputFile._id
),
);
alert("You can download the result");
so sometimes i get empty response with status code 200, was thinking about retrying the request if that happens, am wondering what is the correct way to approach this issue.所以有时我收到状态码为 200 的空响应,正在考虑如果发生这种情况重试请求,我想知道解决此问题的正确方法是什么。
I think axios interceptors will work for you.我认为 axios 拦截器会为你工作。
axios.interceptors.response.use((response) => { return response }, async function(error) { const originalRequest = error.config; if () { // condition originalRequest._retry = true; } } )
You can create setupAxios file in your base redux directory and export it from index.js in your base redux directory.您可以在基本 redux 目录中创建 setupAxios 文件,并将其从基本 redux 目录中的 index.js 导出。
export {default as setupAxios} from "./setupAxios";
And define setupAxios from your root index.js file并从您的根 index.js 文件中定义 setupAxios
import * as _redux from "./redux";
_redux.setupAxios(axios, store);
Btw, I am using react.js, it could be a little different in vue.js.顺便说一句,我使用的是 react.js,它在 vue.js 中可能会有所不同。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.