Merge pull request #1636 from thecodingmachine/no_retry_on_token_decrypted_error

Don't retry Axios if a token decryption failed
This commit is contained in:
David Négrier 2021-12-08 15:32:43 +01:00 committed by GitHub
commit 15bdb0eb56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 8 deletions

View file

@ -13,6 +13,12 @@ axiosWithRetry.defaults.raxConfig = {
maxRetryAfter: 60_000, maxRetryAfter: 60_000,
statusCodesToRetry: [
[100, 199],
[429, 429],
[501, 599],
],
// You can detect when a retry is happening, and figure out how many // You can detect when a retry is happening, and figure out how many
// retry attempts have been made // retry attempts have been made
onRetryAttempt: (err) => { onRetryAttempt: (err) => {

View file

@ -116,11 +116,12 @@ export class Room {
this._contactPage = data.contactPage || CONTACT_URL; this._contactPage = data.contactPage || CONTACT_URL;
return new MapDetail(data.mapUrl, data.textures); return new MapDetail(data.mapUrl, data.textures);
} catch (e) { } catch (e) {
console.error("Error => getMapDetail", e, e.response); if (axios.isAxiosError(e) && e.response?.status == 401 && e.response?.data === "Token decrypted error") {
//TODO fix me and manage Error class console.warn("JWT token sent could not be decrypted. Maybe it expired?");
if (e.response?.data === "Token decrypted error") {
localUserStore.setAuthToken(null); localUserStore.setAuthToken(null);
window.location.assign("/login"); window.location.assign("/login");
} else {
console.error("Error => getMapDetail", e, e.response);
} }
throw e; throw e;
} }

View file

@ -259,6 +259,9 @@ message BanUserMessage{
string message = 2; string message = 2;
} }
/**
* Messages going from back and pusher to the front
*/
message ServerToClientMessage { message ServerToClientMessage {
oneof message { oneof message {
BatchMessage batchMessage = 1; BatchMessage batchMessage = 1;

View file

@ -8,6 +8,7 @@ import { isMapDetailsData, MapDetailsData } from "../Services/AdminApi/MapDetail
import { socketManager } from "../Services/SocketManager"; import { socketManager } from "../Services/SocketManager";
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager"; import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
import { v4 } from "uuid"; import { v4 } from "uuid";
import { InvalidTokenError } from "./InvalidTokenError";
export class MapController extends BaseController { export class MapController extends BaseController {
constructor(private App: TemplatedApp) { constructor(private App: TemplatedApp) {
@ -85,11 +86,15 @@ export class MapController extends BaseController {
userId = authTokenData.identifier; userId = authTokenData.identifier;
console.info("JWT expire, but decoded", userId); console.info("JWT expire, but decoded", userId);
} catch (e) { } catch (e) {
// The token was not good, redirect user on login page if (e instanceof InvalidTokenError) {
res.writeStatus("500"); // The token was not good, redirect user on login page
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL); res.writeStatus("401 Unauthorized");
res.end("Token decrypted error"); res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
return; res.end("Token decrypted error");
return;
} else {
return this.errorToResponse(e, res);
}
} }
} }
} }