16680: Logs out the user when token expires.
authorLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 27 Aug 2020 21:51:53 +0000 (18:51 -0300)
committerLucas Di Pentima <lucas@di-pentima.com.ar>
Thu, 27 Aug 2020 21:51:53 +0000 (18:51 -0300)
Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima <lucas@di-pentima.com.ar>

src/index.tsx
src/services/common-service/common-service.ts

index d07d3c9e025d870077445af3e79a0078c589a763..0a51ed3c8ab94c9fab61d80325f429428ea098d2 100644 (file)
@@ -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
index e00a3d7d43b6ece7be78e55d1e67a0cd5dfe7fda..d605611f46143d8a044379fc56237b2ee7f52fa9 100644 (file)
@@ -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<T> {
             .catch(({ response }) => {
                 actions.progressFn(reqId, false);
                 const errors = CommonService.mapResponseKeys(response) as Errors;
+                errors.status = response.status;
                 actions.errorFn(reqId, errors, showErrors);
                 throw errors;
             });