Axios-module: NFR Set timeout from config

Created on 22 Dec 2018  路  5Comments  路  Source: nuxt-community/axios-module

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.

question

Most helpful comment

And, for anyone prone to overlooking silly stuff, don't forget to 'register' this file under plugins if using 'nuxt.config.js.' 馃う鈥嶁檪

All 5 comments

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.' 馃う鈥嶁檪

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lsbyerley picture lsbyerley  路  4Comments

artmarydotir picture artmarydotir  路  4Comments

lyzs90 picture lyzs90  路  4Comments

altafsayani picture altafsayani  路  3Comments

WtekSupport picture WtekSupport  路  6Comments