Better error message in case of 404
This commit is contained in:
parent
48c3f951bf
commit
4234b38910
@ -1,7 +1,7 @@
|
||||
import {gameManager} from "../Game/GameManager";
|
||||
import {Scene} from "phaser";
|
||||
import {handleAxiosError} from "../../Network/axios";
|
||||
import {ErrorScene} from "../Reconnecting/ErrorScene";
|
||||
import {WAError} from "../Reconnecting/WAError";
|
||||
|
||||
export const EntrySceneName = "EntryScene";
|
||||
|
||||
@ -20,7 +20,11 @@ export class EntryScene extends Scene {
|
||||
gameManager.init(this.scene).then((nextSceneName) => {
|
||||
this.scene.start(nextSceneName);
|
||||
}).catch((err) => {
|
||||
ErrorScene.showError(err, this.scene);
|
||||
if (err.response && err.response.status == 404) {
|
||||
ErrorScene.showError(new WAError('Page Not Found', 'Could not find map', window.location.pathname), this.scene);
|
||||
} else {
|
||||
ErrorScene.showError(err, this.scene);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ import Image = Phaser.GameObjects.Image;
|
||||
import Sprite = Phaser.GameObjects.Sprite;
|
||||
import Text = Phaser.GameObjects.Text;
|
||||
import ScenePlugin = Phaser.Scenes.ScenePlugin;
|
||||
import {WAError} from "./WAError";
|
||||
|
||||
export const ErrorSceneName = "ErrorScene";
|
||||
enum Textures {
|
||||
@ -26,7 +27,7 @@ export class ErrorScene extends Phaser.Scene {
|
||||
});
|
||||
}
|
||||
|
||||
init({ title, subTitle, message }: { title?: string, subTitle?: string, message?: string }) {
|
||||
init({title, subTitle, message}: { title?: string, subTitle?: string, message?: string }) {
|
||||
this.title = title ? title : '';
|
||||
this.subTitle = subTitle ? subTitle : '';
|
||||
this.message = message ? message : '';
|
||||
@ -51,11 +52,14 @@ export class ErrorScene extends Phaser.Scene {
|
||||
|
||||
this.subTitleField = new TextField(this, this.game.renderer.width / 2, this.game.renderer.height / 2 + 24, this.subTitle);
|
||||
|
||||
this.messageField = this.add.text(this.game.renderer.width / 2, this.game.renderer.height / 2 + 38, this.message, { fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif', fontSize: '10px' });
|
||||
this.messageField = this.add.text(this.game.renderer.width / 2, this.game.renderer.height / 2 + 38, this.message, {
|
||||
fontFamily: 'Georgia, "Goudy Bookletter 1911", Times, serif',
|
||||
fontSize: '10px'
|
||||
});
|
||||
this.messageField.setOrigin(0.5, 0.5);
|
||||
|
||||
this.cat = this.physics.add.sprite(this.game.renderer.width / 2, this.game.renderer.height / 2 - 32, 'cat', 6);
|
||||
this.cat.flipY=true;
|
||||
this.cat.flipY = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -69,6 +73,12 @@ export class ErrorScene extends Phaser.Scene {
|
||||
title: 'An error occurred',
|
||||
subTitle: error
|
||||
});
|
||||
} else if (error instanceof WAError) {
|
||||
scene.start(ErrorSceneName, {
|
||||
title: error.title,
|
||||
subTitle: error.subTitle,
|
||||
message: error.details
|
||||
});
|
||||
} else if (error.response) {
|
||||
// Axios HTTP error
|
||||
// client received an error response (5xx, 4xx)
|
||||
@ -95,4 +105,15 @@ export class ErrorScene extends Phaser.Scene {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays the error page, with an error message matching the "error" parameters passed in.
|
||||
*/
|
||||
public static startErrorPage(title: string, subTitle: string, message: string, scene: ScenePlugin): void {
|
||||
scene.start(ErrorSceneName, {
|
||||
title,
|
||||
subTitle,
|
||||
message
|
||||
});
|
||||
}
|
||||
}
|
||||
|
26
front/src/Phaser/Reconnecting/WAError.ts
Normal file
26
front/src/Phaser/Reconnecting/WAError.ts
Normal file
@ -0,0 +1,26 @@
|
||||
export class WAError extends Error {
|
||||
private _title: string;
|
||||
private _subTitle: string;
|
||||
private _details: string;
|
||||
|
||||
constructor (title: string, subTitle: string, details: string) {
|
||||
super(title+' - '+subTitle+' - '+details);
|
||||
this._title = title;
|
||||
this._subTitle = subTitle;
|
||||
this._details = details;
|
||||
// Set the prototype explicitly.
|
||||
Object.setPrototypeOf (this, WAError.prototype);
|
||||
}
|
||||
|
||||
get title(): string {
|
||||
return this._title;
|
||||
}
|
||||
|
||||
get subTitle(): string {
|
||||
return this._subTitle;
|
||||
}
|
||||
|
||||
get details(): string {
|
||||
return this._details;
|
||||
}
|
||||
}
|
@ -22,7 +22,8 @@ import {
|
||||
PusherToBackMessage,
|
||||
AdminPusherToBackMessage,
|
||||
ServerToAdminClientMessage,
|
||||
AdminMessage, SendUserMessage, BanUserMessage
|
||||
SendUserMessage,
|
||||
BanUserMessage
|
||||
} from "../Messages/generated/messages_pb";
|
||||
import {PointInterface} from "../Model/Websocket/PointInterface";
|
||||
import {ProtobufUtils} from "../Model/Websocket/ProtobufUtils";
|
||||
|
Loading…
Reference in New Issue
Block a user