mirror of
https://github.com/sergeyyarkov/educt-client.git
synced 2026-10-11 18:29:15 +03:00
37 lines
914 B
TypeScript
37 lines
914 B
TypeScript
import axios, { AxiosInstance, AxiosRequestConfig } from 'axios';
|
|
import RootStore from 'stores/RootStore';
|
|
|
|
export default class ApiService {
|
|
public root: RootStore;
|
|
|
|
public api: AxiosInstance;
|
|
|
|
public config: AxiosRequestConfig | undefined;
|
|
|
|
constructor(root: RootStore, config?: AxiosRequestConfig | undefined) {
|
|
this.root = root;
|
|
this.config = config;
|
|
this.api = axios.create(this.config);
|
|
this.setupInterceptors();
|
|
}
|
|
|
|
private setupInterceptors() {
|
|
/**
|
|
* Response
|
|
*/
|
|
this.api.interceptors.response.use(undefined, error => {
|
|
if (error.response) {
|
|
/**
|
|
* Unauthorized Error 401
|
|
*/
|
|
if (error.response.status === 401) {
|
|
// this.root.userStore.me = null;
|
|
// this.root.authStore.setIsLoggedIn(false);
|
|
// Cookies.remove('logged_in');
|
|
}
|
|
}
|
|
return Promise.reject(error);
|
|
});
|
|
}
|
|
}
|