Something went wrong. Try again.
notes and lists
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051export const API = { baseURL: "/api/", register: async (name, email, password) => { return await API.send("account/register/", {name, email, password}) }, authenticate: async (email, password) => { return await API.send("account/authenticate/", {email, password}) }, send: async (service, args) => { try { const response = await fetch(API.baseURL + service, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": app.Store.jwt ? `Bearer ${app.Store.jwt}` : null }, body: JSON.stringify(args) }); if (!response.ok){ const errorData = await response.json().catch(()=>({})); throw new Error(errorData.error || `HTTP${response.status}`) } const result = await response.json(); return result; } catch (e) { console.error(e); app.showError(); throw e; } }, fetch: async (serviceName, args)=> { try{ const queryString = args ? new URLSearchParams(args).toString(): ""; const response = await fetch(API.baseURL + serviceName + "?" + queryString,{ headers: { "Authorization": app.Store.jwt ? `Bearer ${app.Store.jwt}` : null }, }); if (!response.ok){ const errorData = await response.json().catch(()=>({})); throw new Error(errorData.error || `HTTP${response.status}`) } const result = await response.json(); return result; } catch (e) { console.error(e); throw e; } },}