Skip to content

Commit 598c741

Browse files
committed
When sending an invalid token, the HTTP API from the Pusher now returns a 401 instead of an HTTP 500.
1 parent ff77a18 commit 598c741

2 files changed

Lines changed: 14 additions & 8 deletions

File tree

front/src/Connexion/Room.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,12 @@ export class Room {
116116
this._contactPage = data.contactPage || CONTACT_URL;
117117
return new MapDetail(data.mapUrl, data.textures);
118118
} catch (e) {
119-
console.error("Error => getMapDetail", e, e.response);
120-
//TODO fix me and manage Error class
121-
if (e.response?.data === "Token decrypted error") {
119+
if (axios.isAxiosError(e) && e.response?.status == 401 && e.response?.data === "Token decrypted error") {
120+
console.warn("JWT token sent could not be decrypted. Maybe it expired?");
122121
localUserStore.setAuthToken(null);
123122
window.location.assign("/login");
123+
} else {
124+
console.error("Error => getMapDetail", e, e.response);
124125
}
125126
throw e;
126127
}

pusher/src/Controller/MapController.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { isMapDetailsData, MapDetailsData } from "../Services/AdminApi/MapDetail
88
import { socketManager } from "../Services/SocketManager";
99
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
1010
import { v4 } from "uuid";
11+
import { InvalidTokenError } from "./InvalidTokenError";
1112

1213
export class MapController extends BaseController {
1314
constructor(private App: TemplatedApp) {
@@ -85,11 +86,15 @@ export class MapController extends BaseController {
8586
userId = authTokenData.identifier;
8687
console.info("JWT expire, but decoded", userId);
8788
} catch (e) {
88-
// The token was not good, redirect user on login page
89-
res.writeStatus("500");
90-
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
91-
res.end("Token decrypted error");
92-
return;
89+
if (e instanceof InvalidTokenError) {
90+
// The token was not good, redirect user on login page
91+
res.writeStatus("401 Unauthorized");
92+
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
93+
res.end("Token decrypted error");
94+
return;
95+
} else {
96+
return this.errorToResponse(e, res);
97+
}
9398
}
9499
}
95100
}

0 commit comments

Comments
 (0)