Initial Commit

Co-authored-by: Subin <subinthattaparambil@gmail.com>
Co-authored-by: Manoj <manojmj92@gmail.com>
Co-authored-by: Nithin <webofnithin@gmail.com>
This commit is contained in:
Pranav Raj Sreepuram
2019-08-14 15:18:44 +05:30
commit 2a34255e0b
537 changed files with 27318 additions and 0 deletions

View File

@@ -0,0 +1,45 @@
/* eslint no-console: 0 */
import constants from '../constants';
import Auth from '../api/auth';
import router from '../routes';
const parseErrorCode = (error) => {
if (error.response) {
if (error.response.status === 401) {
// If auth failed
} else if (error.response.status === 500) {
// If server failed
} else if (error.response.status === 422) {
// If request params are errored
} else if (error.response.status === 901 || error.response.status === 902) {
let name = 'billing_deactivated';
if (Auth.isAdmin()) {
name = 'billing';
}
// If Trial ended
router.push({ name });
} else {
// Anything else
}
} else {
// Something happened in setting up the request that triggered an Error
}
// Do something with request error
return Promise.reject(error);
};
export default (axios) => {
const wootApi = axios.create();
wootApi.defaults.baseURL = constants.apiURL;
// Add Auth Headers to requests if logged in
if (Auth.isLoggedIn()) {
Object.assign(wootApi.defaults.headers.common, Auth.getAuthData());
}
// Response parsing interceptor
wootApi.interceptors.response.use(response => response, error => parseErrorCode(error));
return wootApi;
};