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/events/user-preferences/auto-launch.ts b/src/main/events/user-preferences/auto-launch.ts index 37831db9..cb40a969 100644 --- a/src/main/events/user-preferences/auto-launch.ts +++ b/src/main/events/user-preferences/auto-launch.ts @@ -11,20 +11,22 @@ 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"); + const destination = path.join(windowsStartupPath, "Hydra.vbs"); if (enabled) { const scriptPath = path.join(process.resourcesPath, "hydralauncher.vbs"); 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 { diff --git a/src/main/services/hydra-api.ts b/src/main/services/hydra-api.ts index e5a34cb5..fb8b9a28 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); } ); @@ -146,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); } } } @@ -176,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); } } 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); } 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]);