From 1ceabb00befed60557837dd52486cca887147753 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 28 Jun 2024 11:29:09 -0300 Subject: [PATCH 1/5] feat: better logs on api error --- src/main/events/profile/get-me.ts | 2 +- src/main/services/hydra-api.ts | 16 +++++++++++++++- .../library-sync/merge-with-remote-games.ts | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/main/events/profile/get-me.ts b/src/main/events/profile/get-me.ts index 1225551c..705b14a9 100644 --- a/src/main/events/profile/get-me.ts +++ b/src/main/events/profile/get-me.ts @@ -24,7 +24,7 @@ const getMe = async ( return me; }) .catch((err) => { - logger.error("getMe", err); + logger.error("getMe", err.message); return userAuthRepository.findOne({ where: { id: 1 } }); }); }; diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index e5a34cb5..16b691c9 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -90,7 +90,21 @@ export class HydraApi { return response; }, (error) => { - logger.error("response error", error); + logger.error(" ---- RESPONSE ERROR -----"); + + const { config } = error; + + logger.error(config.method, config.baseURL, config.url, config.headers); + + if (error.response) { + logger.error(error.response.status, error.response.data); + } else if (error.request) { + logger.error(error.request); + } else { + logger.error("Error", error.message); + } + + logger.error(" ----- END RESPONSE ERROR -------"); return Promise.reject(error); } ); diff --git a/src/main/services/library-sync/merge-with-remote-games.ts b/src/main/services/library-sync/merge-with-remote-games.ts index 70a2ee59..3a2db640 100644 --- a/src/main/services/library-sync/merge-with-remote-games.ts +++ b/src/main/services/library-sync/merge-with-remote-games.ts @@ -64,7 +64,7 @@ export const mergeWithRemoteGames = async () => { } } catch (err) { if (err instanceof AxiosError) { - logger.error("getRemoteGames", err.response, err.message); + logger.error("getRemoteGames", err.message); } else { logger.error("getRemoteGames", err); } From c27182c618375bdcf74da1aba4ec435287d15096 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:23:46 -0300 Subject: [PATCH 2/5] feat: navigate back if request fails for get user --- src/renderer/src/pages/user/user.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/renderer/src/pages/user/user.tsx b/src/renderer/src/pages/user/user.tsx index 1068635e..501a61d8 100644 --- a/src/renderer/src/pages/user/user.tsx +++ b/src/renderer/src/pages/user/user.tsx @@ -1,6 +1,6 @@ import { UserProfile } from "@types"; import { useCallback, useEffect, useState } from "react"; -import { useParams } from "react-router-dom"; +import { useNavigate, useParams } from "react-router-dom"; import { setHeaderTitle } from "@renderer/features"; import { useAppDispatch } from "@renderer/hooks"; import { UserSkeleton } from "./user-skeleton"; @@ -12,6 +12,7 @@ import * as styles from "./user.css"; export const User = () => { const { userId } = useParams(); const [userProfile, setUserProfile] = useState(); + const navigate = useNavigate(); const dispatch = useAppDispatch(); @@ -20,6 +21,8 @@ export const User = () => { if (userProfile) { dispatch(setHeaderTitle(userProfile.displayName)); setUserProfile(userProfile); + } else { + navigate(-1); } }); }, [dispatch, userId]); From 4bd2174bf3c4c66fc624b812545a6a5e7f95be22 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 28 Jun 2024 12:24:12 -0300 Subject: [PATCH 3/5] feat: handling 401 status code --- src/main/services/hydra-api.ts | 55 ++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 23 deletions(-) diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index 16b691c9..fb8b9a28 100644 --- a/src/main/services/hydra-api.ts +++ b/src/main/services/hydra-api.ts @@ -160,24 +160,7 @@ export class HydraApi { ["id"] ); } catch (err) { - if ( - err instanceof AxiosError && - (err?.response?.status === 401 || err?.response?.status === 403) - ) { - this.userAuth = { - authToken: "", - expirationTimestamp: 0, - refreshToken: "", - }; - - userAuthRepository.delete({ id: 1 }); - - this.sendSignOutEvent(); - - logger.log("user refresh token expired"); - } - - throw err; + this.handleUnauthorizedError(err); } } } @@ -190,28 +173,54 @@ export class HydraApi { }; } + private static handleUnauthorizedError = (err) => { + if (err instanceof AxiosError && err.response?.status === 401) { + this.userAuth = { + authToken: "", + expirationTimestamp: 0, + refreshToken: "", + }; + + userAuthRepository.delete({ id: 1 }); + + this.sendSignOutEvent(); + } + + throw err; + }; + static async get(url: string) { await this.revalidateAccessTokenIfExpired(); - return this.instance.get(url, this.getAxiosConfig()); + return this.instance + .get(url, this.getAxiosConfig()) + .catch(this.handleUnauthorizedError); } static async post(url: string, data?: any) { await this.revalidateAccessTokenIfExpired(); - return this.instance.post(url, data, this.getAxiosConfig()); + return this.instance + .post(url, data, this.getAxiosConfig()) + .catch(this.handleUnauthorizedError); } static async put(url: string, data?: any) { await this.revalidateAccessTokenIfExpired(); - return this.instance.put(url, data, this.getAxiosConfig()); + return this.instance + .put(url, data, this.getAxiosConfig()) + .catch(this.handleUnauthorizedError); } static async patch(url: string, data?: any) { await this.revalidateAccessTokenIfExpired(); - return this.instance.patch(url, data, this.getAxiosConfig()); + return this.instance + .patch(url, data, this.getAxiosConfig()) + .catch(this.handleUnauthorizedError); } static async delete(url: string) { await this.revalidateAccessTokenIfExpired(); - return this.instance.delete(url, this.getAxiosConfig()); + return this.instance + .delete(url, this.getAxiosConfig()) + .catch(this.handleUnauthorizedError); } } From ed978af3ae6241b60eca457e6c1eb1c1dd15f801 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 28 Jun 2024 13:16:33 -0300 Subject: [PATCH 4/5] feat: disable old windows auto launch --- src/main/events/user-preferences/auto-launch.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/events/user-preferences/auto-launch.ts b/src/main/events/user-preferences/auto-launch.ts index 37831db9..6b73d135 100644 --- a/src/main/events/user-preferences/auto-launch.ts +++ b/src/main/events/user-preferences/auto-launch.ts @@ -11,6 +11,10 @@ const autoLaunch = async ( ) => { if (!app.isPackaged) return; + const appLauncher = new AutoLaunch({ + name: app.getName(), + }); + if (process.platform == "win32") { const destination = path.join(windowsStartupPath, "hydralauncher.vbs"); @@ -19,12 +23,10 @@ const autoLaunch = async ( fs.copyFileSync(scriptPath, destination); } else { + appLauncher.disable().catch(); fs.rmSync(destination); } } else { - const appLauncher = new AutoLaunch({ - name: app.getName(), - }); if (enabled) { appLauncher.enable().catch(); } else { From 7e85ac5b439337e0b5ef6ec392d1dcea7375dbe7 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Fri, 28 Jun 2024 15:35:12 -0300 Subject: [PATCH 5/5] feat: rename vbs file --- src/main/events/user-preferences/auto-launch.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/events/user-preferences/auto-launch.ts b/src/main/events/user-preferences/auto-launch.ts index 6b73d135..cb40a969 100644 --- a/src/main/events/user-preferences/auto-launch.ts +++ b/src/main/events/user-preferences/auto-launch.ts @@ -16,7 +16,7 @@ const autoLaunch = async ( }); if (process.platform == "win32") { - const destination = path.join(windowsStartupPath, "hydralauncher.vbs"); + const destination = path.join(windowsStartupPath, "Hydra.vbs"); if (enabled) { const scriptPath = path.join(process.resourcesPath, "hydralauncher.vbs");