Dear experienced developers I'd really appreciate help with the following.
When running the code below [Chrome Version 100.0.4896.127 (Official Build) (arm64), macOS Monterey Version 12.3] from time to time (intermittently) I get the following error:
net::ERR_HTTP2_PROTOCOL_ERROR 200
and execution stops.
<!DOCTYPE html>
<html>
<head>
<style>
</style>
</head>
<body>
<script>
function sleep(milliseconds)
{
const date = Date.now();
let currentDate = null;
do {
currentDate = Date.now();
} while (currentDate - date < milliseconds);
}
async function doIt()
{
while(true)
{
for (let i = 1; i < 7; i++)
{
let response = await fetch("court"+i+".txt", {cache: "no-store"});
let contents = await response.text();
let components = contents.split(";");
let CourtActive = components[0];
let CourtName = components[1];
let CourtLastUpdate = components [2];
console.log(CourtActive);
console.log(CourtName);
console.log(CourtLastUpdate);
}
sleep(1000);
}
}
doIt();
</script>
</body>
</html>
The contents of courtX.txt is uploaded to the server through ftp and looks like this:
1;CourtX;0
I suspect the error happens when the fetch is executed just when the file is being updated and for some reason Chrome doesn't handle it properly (the error doesn't happens when I use Safari). So my question is how can I intercept the error (try, catch doesn't do it) in such a way that I will only go to the fetch statement if I'm sure the file is stable.
Hope I made myself clear enough and many thanks in advance for any hints.