Could you please add an option to set the timeout in the config?
The default timeout of axios is 0 (infinite) and I would like it to throw an error after x seconds.
This issue as been imported as question since it does not respect axios-module issue template. Only bug reports and feature requests stays open to reduce maintainers workload.
If your issue is not a question, please mention the repo admin or moderator to change its type and it will be re-opened automatically.
Your question is available at https://cmty.app/nuxt/axios-module/issues/c199.
you can set this option inplugins/axios.js, eg:
export default function({ $axios, redirect }) {
$axios.defaults.timeout = 5000;
$axios.onResponse(response => {
return response.data;
});
$axios.onError(error => {
const code = parseInt(error.response && error.response.status);
if (code === 400) {
redirect('/400');
}
});
}
Thnx, but it looks like this will be set on every request instead of using the default value. Will this impact the performance?
No锛宨t won't run in every request. pluginsonly run once in a single page. see:
Nuxt.js allows you to define JavaScript plugins to be run before instantiating the root Vue.js Application
And you can add a console.log after that code and see the prints, so you can prove that.
And, for anyone prone to overlooking silly stuff, don't forget to 'register' this file under plugins if using 'nuxt.config.js.' 馃う鈥嶁檪
Most helpful comment
And, for anyone prone to overlooking silly stuff, don't forget to 'register' this file under
pluginsif using 'nuxt.config.js.' 馃う鈥嶁檪