mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-12-01 20:36:21 -05:00
Displaying plug icon when API fails to respond. Using window.apiDown to communicate to other hooks to stop fetching, the status interval will keep checking if the API is back up.
This commit is contained in:
parent
e7415873a5
commit
01338e4d89
7 changed files with 76 additions and 21 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import React, {useContext, useEffect, useRef, useState} from "react";
|
||||
import {
|
||||
ApiDownError,
|
||||
createChannel,
|
||||
fetchDecoded,
|
||||
fetchDomains,
|
||||
|
|
@ -804,6 +805,9 @@ export const useSettings = () => {
|
|||
const [pending, setPending] = useState(false);
|
||||
|
||||
const fetchSettings = async () => {
|
||||
if (window.apiDown) {
|
||||
return;
|
||||
}
|
||||
setPending(true);
|
||||
try {
|
||||
setSettings(await getSettings())
|
||||
|
|
@ -840,9 +844,15 @@ export const useStatus = () => {
|
|||
|
||||
const fetchStatus = async () => {
|
||||
try {
|
||||
const s = await getStatus();
|
||||
setStatus(s);
|
||||
setStatus(await getStatus());
|
||||
window.apiDown = false;
|
||||
} catch (e) {
|
||||
if (e instanceof ApiDownError) {
|
||||
// API is down, do not log this error.
|
||||
window.apiDown = true;
|
||||
setStatus({});
|
||||
return;
|
||||
}
|
||||
// Ignore SyntaxError because they happen when the API is down.
|
||||
if (!(e instanceof SyntaxError)) {
|
||||
console.error(e);
|
||||
|
|
@ -850,6 +860,11 @@ export const useStatus = () => {
|
|||
}
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
// Used to tell other hooks to stop fetching intervals.
|
||||
window.apiDown = false;
|
||||
}, []);
|
||||
|
||||
return {status, fetchStatus}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue