rgbwifi/web/src/main.js

63 lines
1.4 KiB
JavaScript

import Vue from 'vue'
import VueI18n from 'vue-i18n'
import axios from 'axios'
import App from './App.vue'
import router from './router'
import store from './store'
import messages from './i18n'
// Source: https://github.com/axios/axios/issues/164
axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
const config = err.config;
// If config does not exist or the retry option is not set, reject
if(!config || !config.retry) return Promise.reject(err);
// Set the variable for keeping track of the retry count
config.__retryCount = config.__retryCount || 0;
// Check if we've maxed out the total number of retries
if(config.__retryCount >= config.retry) {
// Reject with the error
return Promise.reject(err);
}
// Increase the retry count
config.__retryCount += 1;
// Create new promise to handle exponential backoff
const backoff = new Promise(function(resolve) {
setTimeout(function() {
resolve();
}, config.retryDelay || 1);
});
// Return the promise in which recalls axios to retry the request
return backoff.then(function() {
return axios(config);
});
});
Vue.use(VueI18n);
const i18n = new VueI18n({
locale: navigator.language.split('-')[0],
fallbackLocale: 'en',
messages: messages
});
Vue.config.productionTip = false;
new Vue({
router,
store,
i18n,
el: '#app',
render: h => h(App)
});