Skip to content

Commit

Permalink
fix: if api 401, reload page by hack fetch, avoid reload more when is…
Browse files Browse the repository at this point in the history
… reloading
  • Loading branch information
whatwewant committed Mar 20, 2024
1 parent d3945a3 commit bd482e9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@
</script>
<script>
var originalFetch = window.fetch;
var isReloading = false;
window.fetch = function (url, options) {
return originalFetch(url, options)
.then(response => {
// if the response is unauthorized, reload the page for re-authentication
if (response.status === 401) {
setTimeout(() => {
window.location.reload();
}, 1000);
if (!isReloading) {
isReloading = true;
setTimeout(() => {
window.location.reload();
}, 1000);
}
} else {
return response;
}
Expand Down

0 comments on commit bd482e9

Please sign in to comment.