better messages, axios client
This commit is contained in:
@@ -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;
|
||||
@@ -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 };
|
||||
Reference in New Issue
Block a user