better messages, axios client

This commit is contained in:
Aria Moradi
2021-03-07 16:27:13 +03:30
parent 954084bd82
commit 7157e07328
7 changed files with 100 additions and 53 deletions
+10
View File
@@ -0,0 +1,10 @@
import axios from 'axios';
import storage from './storage';
const clientMaker = () => axios.create({
baseURL: storage.getItem('baseURL', 'http://127.0.0.1:4567'),
});
const client = clientMaker();
export default client;
+22
View File
@@ -0,0 +1,22 @@
function getItem<T>(key: string, defaultValue: T) : T {
try {
const item = window.localStorage.getItem(key);
if (item !== null) { return JSON.parse(item); }
window.localStorage.setItem(key, JSON.stringify(defaultValue));
} finally {
// eslint-disable-next-line no-unsafe-finally
return defaultValue;
}
}
function setItem<T>(key: string, value: T): void {
try {
window.localStorage.setItem(key, JSON.stringify(value));
// eslint-disable-next-line no-empty
} catch (error) { }
}
export default { getItem, setItem };