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:
commit
15bdb0eb56
@ -13,6 +13,12 @@ axiosWithRetry.defaults.raxConfig = {
|
||||
|
||||
maxRetryAfter: 60_000,
|
||||
|
||||
statusCodesToRetry: [
|
||||
[100, 199],
|
||||
[429, 429],
|
||||
[501, 599],
|
||||
],
|
||||
|
||||
// You can detect when a retry is happening, and figure out how many
|
||||
// retry attempts have been made
|
||||
onRetryAttempt: (err) => {
|
||||
|
@ -116,11 +116,12 @@ export class Room {
|
||||
this._contactPage = data.contactPage || CONTACT_URL;
|
||||
return new MapDetail(data.mapUrl, data.textures);
|
||||
} catch (e) {
|
||||
console.error("Error => getMapDetail", e, e.response);
|
||||
//TODO fix me and manage Error class
|
||||
if (e.response?.data === "Token decrypted error") {
|
||||
if (axios.isAxiosError(e) && e.response?.status == 401 && e.response?.data === "Token decrypted error") {
|
||||
console.warn("JWT token sent could not be decrypted. Maybe it expired?");
|
||||
localUserStore.setAuthToken(null);
|
||||
window.location.assign("/login");
|
||||
} else {
|
||||
console.error("Error => getMapDetail", e, e.response);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
@ -259,6 +259,9 @@ message BanUserMessage{
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Messages going from back and pusher to the front
|
||||
*/
|
||||
message ServerToClientMessage {
|
||||
oneof message {
|
||||
BatchMessage batchMessage = 1;
|
||||
|
@ -8,6 +8,7 @@ import { isMapDetailsData, MapDetailsData } from "../Services/AdminApi/MapDetail
|
||||
import { socketManager } from "../Services/SocketManager";
|
||||
import { AuthTokenData, jwtTokenManager } from "../Services/JWTTokenManager";
|
||||
import { v4 } from "uuid";
|
||||
import { InvalidTokenError } from "./InvalidTokenError";
|
||||
|
||||
export class MapController extends BaseController {
|
||||
constructor(private App: TemplatedApp) {
|
||||
@ -85,11 +86,15 @@ export class MapController extends BaseController {
|
||||
userId = authTokenData.identifier;
|
||||
console.info("JWT expire, but decoded", userId);
|
||||
} catch (e) {
|
||||
// The token was not good, redirect user on login page
|
||||
res.writeStatus("500");
|
||||
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
||||
res.end("Token decrypted error");
|
||||
return;
|
||||
if (e instanceof InvalidTokenError) {
|
||||
// The token was not good, redirect user on login page
|
||||
res.writeStatus("401 Unauthorized");
|
||||
res.writeHeader("Access-Control-Allow-Origin", FRONT_URL);
|
||||
res.end("Token decrypted error");
|
||||
return;
|
||||
} else {
|
||||
return this.errorToResponse(e, res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user