Ade Mustofa
2 years ago
3 changed files with 181 additions and 139 deletions
@ -0,0 +1,41 @@
|
||||
import axios from 'axios'; |
||||
export default class RequestApi { |
||||
// constructor() {
|
||||
// this.Request = this.Request.bind(this);
|
||||
// }
|
||||
|
||||
static Request() { |
||||
// axios.interceptors.request.use(function (config) {
|
||||
// const token = localStorage.getItem('token')
|
||||
// config.headers.Authorization = token;
|
||||
|
||||
// return config;
|
||||
// });
|
||||
const token = localStorage.getItem('token') |
||||
|
||||
let instance = axios.create({ |
||||
headers: { |
||||
'Content-Type': 'application/json', |
||||
"Authorization": `Bearer ${token}` |
||||
} |
||||
}) |
||||
|
||||
instance.interceptors.response.use( |
||||
(response) => response, |
||||
async (error) => { |
||||
// const originalRequest = error.config;
|
||||
if (error.response.status === 307 || error.response.status === 403) { |
||||
console.log(error.response); |
||||
} |
||||
|
||||
return Promise.reject(error); |
||||
} |
||||
); |
||||
|
||||
return instance; |
||||
} |
||||
|
||||
static getToken() { } |
||||
} |
||||
export const AXIOS = RequestApi.Request(); |
||||
|
Loading…
Reference in new issue