mirror of
https://github.com/Sendouc/sendou.ink.git
synced 2026-05-09 12:13:10 -05:00
16 lines
436 B
TypeScript
16 lines
436 B
TypeScript
export async function sendData(method = "POST", url = "", data = {}) {
|
|
// Default options are marked with *
|
|
const response = await fetch(url, {
|
|
method,
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify(data),
|
|
});
|
|
|
|
if (response.status < 200 || response.status > 299) {
|
|
// FIXME: different messages for different status codes and translated
|
|
throw Error("Invalid request");
|
|
}
|
|
}
|