Browse Source

update request

pull/2/head
Ade Mustofa 2 years ago
parent
commit
c246db4e6c
  1. 2
      src/containers/DefaultLayout/DefaultLayout.js
  2. 41
      src/services/base.js
  3. 3
      src/views/Map/Map_16.js

2
src/containers/DefaultLayout/DefaultLayout.js

@ -152,7 +152,7 @@ class DefaultLayout extends Component {
}
if (countErr) {
if (parseInt(countErr) > 2) {
this.signOut();
// this.signOut();
} else {
window.location.reload();
}

41
src/services/base.js

@ -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();

3
src/views/Map/Map_16.js

@ -123,6 +123,7 @@ import * as lodash from 'lodash';
import { Pie, Line, Bar } from 'react-chartjs-2';
import numeral from 'numeral';
import { NotificationContainer, NotificationManager } from 'react-notifications';
import { AXIOS } from '../../services/base'
import 'chartjs-plugin-zoom';
const HEADER = {
@ -2907,7 +2908,7 @@ class SiopasMap extends Component {
body: JSON.stringify(payload) // body data type must match "Content-Type" header
}
try {
const result = await fetch(url, config).then(response => response.json()).then(res => res);
const result = await AXIOS.post(url, payload).then(response => response.json()).then(res => res);
return result.data || []
}
catch (e) {

Loading…
Cancel
Save