Blame view
src/Services/http.js
2.01 KB
03dcbf0c1
|
1 2 |
import axios from 'axios' import store from '@/store/store' |
6e1cb5c96
|
3 |
import Vue from 'vue' |
5d5315b0f
|
4 |
import { vm1 } from "@/main.js" |
03dcbf0c1
|
5 |
|
11d037abe
|
6 |
const baseDomain = "https://api-dashboard.intrack.in/v1"; |
29ac0dbb2
|
7 8 |
const baseURL = `${baseDomain}`; |
8deade193
|
9 10 11 12 13 14 15 16 17 |
// var token = "" // if (store.state.role === "ADMIN") { // token = `${store.state.token}` // } else if (store.state.schoolRole === "SUPERADMIN") { // token = `${store.state.schoolToken}` // } // console.log("role",`${store.state.schoolRole}`); // console.log("token",`${store.state.schoolToken}`); |
6e1cb5c96
|
18 |
|
03dcbf0c1
|
19 |
export default () => { |
4ecd35af2
|
20 21 22 23 24 25 26 27 28 29 30 31 |
// return axios.create({ // // baseURL: 'http://192.168.2.221:3002/v1', // baseURL, // headers: { // Authorization: `Bearer ${store.state.token}` // } // }) let instance = axios.create({ // LIVE //baseURL: 'https://annadata.patanjaliayurved.org/api', // DEVELOPMENT baseURL: baseURL, |
6e1cb5c96
|
32 |
|
4ecd35af2
|
33 34 35 36 |
headers: { Authorization: `Bearer ${store.state.token}`, // Authorization: `Bearer sdfsdfsfsdf`, // 'Access-Control-Allow-Origin': '*' |
6e1cb5c96
|
37 |
|
4ecd35af2
|
38 39 |
} }) |
6e1cb5c96
|
40 |
|
4ecd35af2
|
41 42 |
instance.interceptors.request.use((config) => { // Do something before request is sent |
6e1cb5c96
|
43 |
|
4ecd35af2
|
44 45 46 47 48 49 50 51 52 53 54 55 |
return config }, error => { return Promise.reject(error) }) instance.interceptors.response.use((response) => { // do something with the response data return response; }, error => { // handle the response error console.log("error in interceptor - ", error.response.status) var customError const errorNo = error.response.status |
6e1cb5c96
|
56 |
|
4ecd35af2
|
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
switch (errorNo) { case 401: customError = "Session expired" vm1.$store.dispatch("RESET_STORE", { token: null, data: null, isUserLoggedIn: false, isSchoolLoggedIn: false, id: null, role: null, // schoolId: null, schoolToken: null, schoolRole: null, studentsData: [], }); window.getApp.$emit("APP_LOGOUT"); console.log("store is - ", vm1.$store.state) vm1.$router.push({ name: "Login" }); // vm1.$store.dispatch("Id", null); |
6e1cb5c96
|
76 |
|
4ecd35af2
|
77 78 |
break; } |
6e1cb5c96
|
79 |
|
4ecd35af2
|
80 81 82 |
return Promise.reject(error); }) // response parse |
5d5315b0f
|
83 |
|
4ecd35af2
|
84 |
return instance; |
04165779e
|
85 |
} |