Skip to content
This repository was archived by the owner on Jul 23, 2023. It is now read-only.

Commit 0798226

Browse files
committed
Hide alert if not able to fetch
1 parent 6ec4d04 commit 0798226

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

app/components/AppAlert.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export const AppAlert = () => {
3737
updateAlert();
3838
}, [alertSourceUrl]);
3939

40-
if (!alert || !alert.enabled) {
40+
if (!alertSourceUrl || !alert || !alert.enabled) {
4141
return null;
4242
}
4343

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
import { debugConsole } from '../helpers/console-log';
2+
13
export type ModManagerAlert = {
24
enabled: boolean;
35
message: string;
46
};
57

68
export async function getModManagerAlert(
7-
url: string
9+
url: string,
810
): Promise<ModManagerAlert> {
9-
const response = await fetch(url);
11+
try {
12+
const response = await fetch(url);
1013

11-
if (!response.ok) {
12-
throw new Error(`${response.statusText} (${response.status})`);
13-
}
14+
if (!response.ok) {
15+
throw new Error(`${response.statusText} (${response.status})`);
16+
}
1417

15-
return (await response.json()) as ModManagerAlert;
18+
return (await response.json()) as ModManagerAlert;
19+
} catch (error) {
20+
debugConsole.error(`Failed to get alert: ${error}`);
21+
return { enabled: false, message: '' };
22+
}
1623
}

0 commit comments

Comments
 (0)