fix possibility of 404 on home if getRandomGame has no validy elements to return

this can happen when user has no internet connection when opening hydra
This commit is contained in:
Zamitto 2024-04-27 20:43:34 -03:00
parent 2904302c81
commit a8b236e02c
2 changed files with 21 additions and 20 deletions

View file

@ -7,7 +7,9 @@ export interface Steam250Game {
}
export const requestSteam250 = async (path: string) => {
return axios.get(`https://steam250.com${path}`).then((response) => {
return axios
.get(`https://steam250.com${path}`)
.then((response) => {
const { window } = new JSDOM(response.data);
const { document } = window;
@ -22,7 +24,8 @@ export const requestSteam250 = async (path: string) => {
} as Steam250Game;
})
.filter((game) => game != null);
});
})
.catch((_) => []);
};
const steam250Paths = [

View file

@ -58,13 +58,11 @@ export function Home() {
const getRandomGame = useCallback(() => {
setIsLoadingRandomGame(true);
window.electron
.getRandomGame()
.then((objectID) => {
window.electron.getRandomGame().then((objectID) => {
if (objectID) {
randomGameObjectID.current = objectID;
})
.finally(() => {
setIsLoadingRandomGame(false);
}
});
}, []);