Refactoring Error Screen

This commit is contained in:
CEC
2022-04-12 10:23:36 +02:00
parent e13fec1a8b
commit ecabdbe0c0
19 changed files with 315 additions and 61 deletions
@@ -318,6 +318,8 @@ export class AuthenticateController extends BaseHttpController {
(async () => {
const param = await req.json();
adminApi.setLocale(req.header('accept-language'));
//todo: what to do if the organizationMemberToken is already used?
const organizationMemberToken: string | null = param.organizationMemberToken;
const playUri: string | null = param.playUri;
+8 -6
View File
@@ -31,12 +31,14 @@ export class BaseHttpController {
if (axios.isAxiosError(e) && e.response) {
res.status(e.response.status);
res.send(
"An error occurred: " +
e.response.status +
" " +
(e.response.data && e.response.data.message ? e.response.data.message : e.response.statusText)
);
if(!e.response.data?.code) {
res.send(
"An error occurred: " +
e.response.status +
" " +
(e.response.data && e.response.data.message ? e.response.data.message : e.response.statusText)
);
} else res.json(e.response.data);
return;
} else {
res.status(500);
+13 -9
View File
@@ -69,7 +69,7 @@ interface UpgradeData {
interface UpgradeFailedData {
rejected: true;
reason: "tokenInvalid" | "textureInvalid" | null;
reason: "tokenInvalid" | "textureInvalid" | "error" | null;
message: string;
roomId: string;
}
@@ -236,6 +236,8 @@ export class IoSocketController {
const websocketExtensions = req.getHeader("sec-websocket-extensions");
const IPAddress = req.getHeader("x-forwarded-for");
adminApi.setLocale(req.getHeader('accept-language'));
const roomId = query.roomId;
try {
if (typeof roomId !== "string") {
@@ -311,7 +313,7 @@ export class IoSocketController {
);
} catch (err) {
if (Axios.isAxiosError(err)) {
if (err?.response?.status == 404) {
if (err?.response?.status == 404 || !err?.response?.data.code) {
// If we get an HTTP 404, the token is invalid. Let's perform an anonymous login!
console.warn(
@@ -319,16 +321,18 @@ export class IoSocketController {
(userIdentifier || "anonymous") +
'". Performing an anonymous login instead.'
);
} else if (err?.response?.status == 403) {
// If we get an HTTP 403, the world is full. We need to broadcast a special error to the client.
// we finish immediately the upgrade then we will close the socket as soon as it starts opening.
} else if (err?.response?.data.code) {
//OLD // If we get an HTTP 403, the world is full. We need to broadcast a special error to the client.
//OLD // we finish immediately the upgrade then we will close the socket as soon as it starts opening.
return res.upgrade(
{
rejected: true,
message: err?.response?.data.message,
reason: "error",
message: err?.response?.data.code,
status: err?.response?.status,
error: err?.response?.data,
roomId,
},
} as UpgradeFailedData,
websocketKey,
websocketProtocol,
websocketExtensions,
@@ -481,8 +485,8 @@ export class IoSocketController {
socketManager.emitTokenExpiredMessage(ws);
} else if (ws.reason === "textureInvalid") {
socketManager.emitInvalidTextureMessage(ws);
} else if (ws.message === "World is full") {
socketManager.emitWorldFullMessage(ws);
} else if (ws.reason === "error") {
socketManager.emitErrorV2Message(ws, ws.error.type, ws.error.code, ws.error.title, ws.error.subtitle, ws.error.details, ws.error.timeToRetry, ws.error.canRetryManual, ws.error.urlToRedirect, ws.error.buttonTitle);
} else {
socketManager.emitConnexionErrorMessage(ws, ws.message);
}