UNPKG

@piarre/ts-freebox

Version:

28 lines (26 loc) 726 B
// src/utils/fetch.ts var formatUrl = (url) => !url.toString().endsWith("/") ? `${url}/` : url; var fetchFBX = (url, token, method, options) => { return fetch(formatUrl(url), { ...options, method, body: JSON.stringify(options?.body), headers: { ...options?.headers, "Content-Type": "application/json", "X-Fbx-App-Auth": token || "", Host: "mafreebox.freebox.fr" } }).then((res) => res.json()).catch((error) => { throw new Error(`\u274C ~ error on call ${url}`, { cause: error }); }); }; var request = (url, token, options, method = "GET") => fetchFBX(url, token, method, options); var fetch_default = request; export { fetchFBX, request, fetch_default };