32 lines
758 B
TypeScript

/* Base domain for all request */
export const baseURL = import.meta.env.VITE_URL_DOCUMENT
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
}
class SimpleError extends Error implements ISimpleError {
code : number
constructor(code: number, message:string) {
super(message)
this.code = code
}
}
export default Client