{"size": 1123, "ext": "js", "max_stars_repo_path": "src/services/AxiosInstance.js", "max_stars_repo_name": "Juanperezc/variacode-frontend", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/services/AxiosInstance.js", "max_issues_repo_name": "Juanperezc/variacode-frontend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/services/AxiosInstance.js", "max_forks_repo_name": "Juanperezc/variacode-frontend", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 24.4130434783, "max_line_length": 65, "alphanum_fraction": 0.5877114871}
import axios from 'axios'
import ConfigStorage from './storage/config.store'

 //'http://127.0.0.1:3333'
//'http://157.56.176.217'

const axiosInstance = axios.create({
    baseURL: 'http://127.0.0.1:3000',
    timeout: 20000,
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }
})

axiosInstance.interceptors.request.use(
     (config) => {
        // Do something before request is sent
        const token =  ConfigStorage.getToken();
        config.headers["Authorization"] = "Bearer " + token;
        return config;
    },
    error => {
      Promise.reject(error);
    }
  );

  axiosInstance.interceptors.response.use(  async (response) => {
        return response;
   }, (error) => {
     if (!error.response) {
        return Promise.reject('Network Error')
     }
     else if ((error.response.status === 401) ){
         ConfigStorage.clearSession();
         return Promise.reject('Invalid Token')
          .finally(()=> window.location = "/login?exp=true")
     }
    else {
       
         return error.response
      }
 })

export default axiosInstance
