Last active
July 29, 2019 17:59
-
-
Save JosielFaleiros/5f9a15459592343d8660a184596005b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
const instance = axios.create({ | |
baseURL: 'https://baseurl', | |
headers: { | |
'Content-Type': 'application/json' | |
} | |
}); | |
instance.interceptors.response.use((interceptedRequest) => { | |
if (interceptedRequest.data && interceptedRequest.data.updateToken) { | |
} | |
return interceptedRequest; | |
}, err => Promise.reject(err)); | |
const get = function (url, config) { | |
return new Promise((resolve, reject) => { | |
if (localStorage.getItem(url)) { | |
resolve(JSON.parse(localStorage.getItem(url))); | |
} else { | |
instance.get(url, config) | |
.then((data) => { | |
console.log('url to set ', url); | |
localStorage.setItem(url, (JSON.stringify(data))); | |
resolve(data); | |
}) | |
.catch(reject); | |
} | |
}); | |
}; | |
export default { ...instance, get }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment