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

Commit

Permalink
Hide alert if not able to fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
Raicuparta committed Jul 23, 2023
1 parent 6ec4d04 commit 0798226
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/components/AppAlert.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const AppAlert = () => {
updateAlert();
}, [alertSourceUrl]);

if (!alert || !alert.enabled) {
if (!alertSourceUrl || !alert || !alert.enabled) {
return null;
}

Expand Down
19 changes: 13 additions & 6 deletions app/services/get-mod-manager-alert.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { debugConsole } from '../helpers/console-log';

export type ModManagerAlert = {
enabled: boolean;
message: string;
};

export async function getModManagerAlert(
url: string
url: string,
): Promise<ModManagerAlert> {
const response = await fetch(url);
try {
const response = await fetch(url);

if (!response.ok) {
throw new Error(`${response.statusText} (${response.status})`);
}
if (!response.ok) {
throw new Error(`${response.statusText} (${response.status})`);
}

return (await response.json()) as ModManagerAlert;
return (await response.json()) as ModManagerAlert;
} catch (error) {
debugConsole.error(`Failed to get alert: ${error}`);
return { enabled: false, message: '' };
}
}

0 comments on commit 0798226

Please sign in to comment.