From 202a49e579c8ba643f6bc7f2bcb55fcf57d12eb8 Mon Sep 17 00:00:00 2001 From: Lucas Di Pentima Date: Thu, 27 Aug 2020 18:51:53 -0300 Subject: [PATCH] 16680: Logs out the user when token expires. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- src/index.tsx | 6 ++++-- src/services/common-service/common-service.ts | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index d07d3c9e..0a51ed3c 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -14,7 +14,7 @@ import { configureStore, RootStore } from '~/store/store'; import { ConnectedRouter } from "react-router-redux"; import { ApiToken } from "~/views-components/api-token/api-token"; import { AddSession } from "~/views-components/add-session/add-session"; -import { initAuth } from "~/store/auth/auth-action"; +import { initAuth, logout } from "~/store/auth/auth-action"; import { createServices } from "~/services/services"; import { MuiThemeProvider } from '@material-ui/core/styles'; import { CustomTheme } from '~/common/custom-theme'; @@ -108,8 +108,10 @@ fetchConfig() if (showSnackBar) { console.error("Backend error:", error); - if (error.errors[0].indexOf("not found") > -1) { + if (error.status === 404) { store.dispatch(openNotFoundDialog()); + } else if (error.status === 401 && error.errors[0].indexOf("Not logged in") > -1) { + store.dispatch(logout()); } else { store.dispatch(snackbarActions.OPEN_SNACKBAR({ message: `${error.errors diff --git a/src/services/common-service/common-service.ts b/src/services/common-service/common-service.ts index e00a3d7d..d605611f 100644 --- a/src/services/common-service/common-service.ts +++ b/src/services/common-service/common-service.ts @@ -9,6 +9,7 @@ import { ApiActions } from "~/services/api/api-actions"; import * as QueryString from "query-string"; interface Errors { + status: number; errors: string[]; errorToken: string; } @@ -80,6 +81,7 @@ export class CommonService { .catch(({ response }) => { actions.progressFn(reqId, false); const errors = CommonService.mapResponseKeys(response) as Errors; + errors.status = response.status; actions.errorFn(reqId, errors, showErrors); throw errors; }); -- 2.30.2