Change type of unauthorized (#2123)
* Change type of unauthorized * Fix redirect on received erroScreenMessage from API
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { fly } from "svelte/transition";
|
||||
import { errorScreenStore } from "../../Stores/ErrorScreenStore";
|
||||
import { gameManager } from "../../Phaser/Game/GameManager";
|
||||
import { connectionManager } from "../../Connexion/ConnectionManager";
|
||||
import { get } from "svelte/store";
|
||||
import { onDestroy } from "svelte";
|
||||
|
||||
@@ -11,7 +12,8 @@
|
||||
let errorScreen = get(errorScreenStore);
|
||||
|
||||
function click() {
|
||||
window.location.reload();
|
||||
if (errorScreen.type === "unauthorized") void connectionManager.logout();
|
||||
else window.location.reload();
|
||||
}
|
||||
let details = errorScreen.details;
|
||||
let timeVar = errorScreen.timeToRetry ?? 0;
|
||||
@@ -37,9 +39,9 @@
|
||||
<p class="details">
|
||||
{detailsStylized}{#if $errorScreenStore.type === "retry"}<div class="loading" />{/if}
|
||||
</p>
|
||||
{#if $errorScreenStore.type === "retry" && $errorScreenStore.canRetryManual}
|
||||
{#if ($errorScreenStore.type === "retry" && $errorScreenStore.canRetryManual) || $errorScreenStore.type === "unauthorized"}
|
||||
<button type="button" class="nes-btn is-primary button" on:click={click}>
|
||||
<img src={reload} alt="" class="reload" />
|
||||
{#if $errorScreenStore.type === "retry"}<img src={reload} alt="" class="reload" />{/if}
|
||||
{$errorScreenStore.buttonTitle}
|
||||
</button>
|
||||
{/if}
|
||||
|
||||
@@ -483,9 +483,15 @@ export class RoomConnection implements RoomConnection {
|
||||
}
|
||||
case "errorScreenMessage": {
|
||||
this._errorScreenMessageStream.next(message.errorScreenMessage);
|
||||
if (message.errorScreenMessage.code !== "retry") this.closed = true;
|
||||
console.error("An error occurred server side: " + message.errorScreenMessage.code);
|
||||
errorScreenStore.setError(message.errorScreenMessage);
|
||||
console.error("An error occurred server side: " + JSON.stringify(message.errorScreenMessage));
|
||||
if (message.errorScreenMessage.code !== "retry") {
|
||||
this.closed = true;
|
||||
}
|
||||
if (message.errorScreenMessage.type === "redirect" && message.errorScreenMessage.urlToRedirect) {
|
||||
window.location.assign(message.errorScreenMessage.urlToRedirect);
|
||||
} else {
|
||||
errorScreenStore.setError(message.errorScreenMessage);
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
|
||||
@@ -6,7 +6,6 @@ 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";
|
||||
|
||||
@@ -49,9 +48,7 @@ export class EntryScene extends Scene {
|
||||
.catch((err) => {
|
||||
const errorType = isErrorApiData.safeParse(err?.response?.data);
|
||||
if (errorType.success) {
|
||||
if (errorType.data.type === "unauthorized") {
|
||||
void connectionManager.logout();
|
||||
} else if (errorType.data.type === "redirect") {
|
||||
if (errorType.data.type === "redirect") {
|
||||
window.location.assign(errorType.data.urlToRedirect);
|
||||
} else errorScreenStore.setError(err?.response?.data);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user