sendou.ink/lib/postData.ts
2020-11-08 01:16:13 +02:00

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");
}
}