Build down to 90 kB, 1.5 MB less after removing ant-design.

This commit is contained in:
Leo Vasanko
2023-11-02 22:33:21 +00:00
parent 831b2716f7
commit 6cba674b30
12 changed files with 79 additions and 318 deletions

View File

@@ -1,32 +1,21 @@
import axios, {AxiosError} from 'axios'
/* Base domain for all request */
export const baseURL = import.meta.env.VITE_URL_DOCUMENT
/* Config Client*/
const Client = axios.create({
baseURL: baseURL,
headers: {
Accept: 'application/json',
},
})
Client.interceptors.response.use(
(response) => {
// Any status code that lie within the range of 2xx cause this function to trigger
// Do something with response data
return response
},
(error: AxiosError<any>) => {
const msg = error.response && error.response.data && error.response.data.error ?
error.response.data.error.message : 'Unexpected error'
const code = error.code ? Number(error.response?.status) : 500
const standardizedError = new SimpleError(code, msg)
return Promise.reject(standardizedError)
class ClientClass {
async post(url: string, data?: Record<string, any>): Promise<any> {
const res = await fetch(`${baseURL}/`, {
method: "POST",
headers: {
accept: 'application/json',
"content-type": 'application/json',
},
body: data !== undefined ? JSON.stringify(data) : undefined,
})
return await res.json()
}
)
}
export const Client = new ClientClass()
export interface ISimpleError extends Error {
code : number
}