Skip to content

Commit

Permalink
basic error handling for server fetches
Browse files Browse the repository at this point in the history
  • Loading branch information
nedbat committed Jul 24, 2021
1 parent f4da72d commit 74a9bdf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/aptus/web/static/aptus.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,15 @@ function fetchTile(tile) {
spec: tile.spec,
};
fetch_post_json("/tile", body)
.then(response => response.json())
.then(tiledata => {
if (tiledata.seq == tile.view.reqseq) {
tile.img = new Image();
tile.img.src = tiledata.url;
tile.img.onload = () => resolve(tile);
}
});
.then(response => response.json())
.then(tiledata => {
if (tiledata.seq == tile.view.reqseq) {
tile.img = new Image();
tile.img.src = tiledata.url;
tile.img.onload = () => resolve(tile);
}
})
.catch(() => {});
});
}

Expand All @@ -248,6 +249,17 @@ function fetch_post_json(url, body) {
headers: {
"Content-Type": "application/json",
},
})
.then(response => {
if (!response.ok) {
throw new Error(`${response.status}: ${response.statusText}`);
}
return response;
})
.catch(error => {
document.querySelector("#problempanel p").innerHTML = error;
Panels.show_panel("#problempanel");
return Promise.reject(error);
});
}

Expand Down
5 changes: 5 additions & 0 deletions src/aptus/web/templates/mainpage.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@
<p id="linklink"></p>
</div>

<div id="problempanel" class="panel draggable">
{{closebtn}}
<p></p>
</div>

<script>
document.body.onload = main;
</script>
Expand Down

0 comments on commit 74a9bdf

Please sign in to comment.