nelle-observer/frontend/public/scripts/api.js
2024-10-30 19:59:07 -06:00

55 lines
1.5 KiB
JavaScript

function handleErrors(response) {
if (!response.ok) {
throw Error(response.statusText);
}
return response;
}
function sendMeow(endpoint) {
const request = new XMLHttpRequest();
request.open("POST", endpoint);
request.send("superSecret=null");
console.warn(request.response.text);
}
async function getMeowTimeout(endpoint) {
const response = await fetch(endpoint);
if (response.status === 423) {
meowButton.disabled = true;
meowButton.innerHTML = "<span>sleeping...</span>";
console.warn("MEOW TIMED OUT");
}
if (response.status === 100) {
meowButton.disabled = false;
meowButton.innerHTML = "<span>meow</span>";
console.warn("MEOW NOT TIMED OUT");
}
}
async function getBeepTimeout(endpoint) {
const response = await fetch(endpoint);
if (response.status === 423) {
beepButton.disabled = true;
beepButton.innerHTML = "<span>sleeping...</span>";
console.warn("BEEP TIMED OUT");
}
if (response.status === 100) {
beepButton.disabled = false;
beepButton.innerHTML = "<span>meow</span>";
console.warn("BEEP NOT TIMED OUT");
}
}
async function getKaomojiTimeout(endpoint) {
const response = await fetch(endpoint);
if (response.status === 423) {
kaomojiButton.disabled = true;
kaomojiButton.innerHTML = "<span>sleeping...</span>";
console.warn("KAOMOJI TIMED OUT");
}
if (response.status === 100) {
kaomojiButton.disabled = false;
kaomojiButton.innerHTML = "<span>meow</span>";
console.warn("KAOMOJI NOT TIMED OUT");
}
}