Add redirect directly without showing ErrorScreen

This commit is contained in:
CEC 2022-04-20 10:54:27 +02:00
parent 60ec09836b
commit 8d771d8442
2 changed files with 10 additions and 5 deletions

View File

@ -13,12 +13,10 @@
let errorScreen = get(errorScreenStore); let errorScreen = get(errorScreenStore);
if (!errorScreen.buttonTitle && errorScreen.urlToRedirect) window.location.replace(errorScreen.urlToRedirect);
function click() { function click() {
if (errorScreen.urlToRedirect) { if (errorScreen.urlToRedirect) {
if (errorScreen.urlToRedirect === "/login") void connectionManager.logout(); 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 if (errorScreen.type === "redirect" && window.history.length > 2) history.back();
else window.location.reload(); else window.location.reload();
} }

View File

@ -5,6 +5,8 @@ import { waScaleManager } from "../Services/WaScaleManager";
import { ReconnectingTextures } from "../Reconnecting/ReconnectingScene"; import { ReconnectingTextures } from "../Reconnecting/ReconnectingScene";
import { localeDetector } from "../../i18n/locales"; import { localeDetector } from "../../i18n/locales";
import { errorScreenStore } from "../../Stores/ErrorScreenStore"; import { errorScreenStore } from "../../Stores/ErrorScreenStore";
import {isErrorApiData} from "../../Messages/JsonMessages/ErrorApiData";
import {connectionManager} from "../../Connexion/ConnectionManager";
export const EntrySceneName = "EntryScene"; export const EntrySceneName = "EntryScene";
@ -45,8 +47,13 @@ export class EntryScene extends Scene {
this.scene.start(nextSceneName); this.scene.start(nextSceneName);
}) })
.catch((err) => { .catch((err) => {
if (err?.response?.data?.code) { const errorType = isErrorApiData.safeParse(err?.response?.data);
errorScreenStore.setError(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 { } else {
ErrorScene.showError(err, this.scene); ErrorScene.showError(err, this.scene);
} }