28 lines
703 B
JavaScript
28 lines
703 B
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 === 500) {
|
||
|
meowButton.disabled=true;
|
||
|
meowButton.innerHTML = "<span>sleeping...</span>";
|
||
|
console.warn("TIMED OUT")
|
||
|
}
|
||
|
if (response.status === 200) {
|
||
|
meowButton.disabled=false;
|
||
|
meowButton.innerHTML = "<span>meow</span>";
|
||
|
console.warn("NOT TIMED OUT")
|
||
|
}
|
||
|
}
|