diff --git a/front/src/Components/UI/ErrorScreen.svelte b/front/src/Components/UI/ErrorScreen.svelte index b51708c3..71b33456 100644 --- a/front/src/Components/UI/ErrorScreen.svelte +++ b/front/src/Components/UI/ErrorScreen.svelte @@ -13,12 +13,10 @@ let errorScreen = get(errorScreenStore); - if (!errorScreen.buttonTitle && errorScreen.urlToRedirect) window.location.replace(errorScreen.urlToRedirect); - function click() { if (errorScreen.urlToRedirect) { if (errorScreen.urlToRedirect === "/login") void connectionManager.logout(); - else window.location.replace(errorScreen.urlToRedirect); + else window.location.assign(errorScreen.urlToRedirect); } else if (errorScreen.type === "redirect" && window.history.length > 2) history.back(); else window.location.reload(); } diff --git a/front/src/Phaser/Login/EntryScene.ts b/front/src/Phaser/Login/EntryScene.ts index c7f01d13..7c08f537 100644 --- a/front/src/Phaser/Login/EntryScene.ts +++ b/front/src/Phaser/Login/EntryScene.ts @@ -5,6 +5,8 @@ import { waScaleManager } from "../Services/WaScaleManager"; import { ReconnectingTextures } from "../Reconnecting/ReconnectingScene"; import { localeDetector } from "../../i18n/locales"; import { errorScreenStore } from "../../Stores/ErrorScreenStore"; +import {isErrorApiData} from "../../Messages/JsonMessages/ErrorApiData"; +import {connectionManager} from "../../Connexion/ConnectionManager"; export const EntrySceneName = "EntryScene"; @@ -45,8 +47,13 @@ export class EntryScene extends Scene { this.scene.start(nextSceneName); }) .catch((err) => { - if (err?.response?.data?.code) { - errorScreenStore.setError(err.response.data); + const errorType = isErrorApiData.safeParse(err?.response?.data); + if (errorType.success) { + // If error from API and urlToRedirect is specified but not buttonTitle => redirect directly + if (!errorType.data.buttonTitle && errorType.data.urlToRedirect){ + if (errorType.data.urlToRedirect === "/login") void connectionManager.logout(); + else window.location.assign(errorType.data.urlToRedirect); + } else errorScreenStore.setError(err.response.data); } else { ErrorScene.showError(err, this.scene); }