diff --git a/client/src/api/Api.js b/client/src/api/Api.js index d8fed5ce..3d215144 100644 --- a/client/src/api/Api.js +++ b/client/src/api/Api.js @@ -1,6 +1,7 @@ import axios from 'axios'; import { getPathWithQueryString } from '../helpers/helpers'; +import { R_PATH_LAST_PART } from '../helpers/constants'; class Api { baseUrl = 'control'; @@ -17,6 +18,12 @@ class Api { console.error(error); const errorPath = `${this.baseUrl}/${path}`; if (error.response) { + if (error.response.status === 403) { + const loginPageUrl = window.location.href.replace(R_PATH_LAST_PART, '/login.html'); + window.location.replace(loginPageUrl); + return false; + } + throw new Error(`${errorPath} | ${error.response.data} | ${error.response.status}`); } throw new Error(`${errorPath} | ${error.message ? error.message : error}`); diff --git a/client/src/helpers/constants.js b/client/src/helpers/constants.js index f186bfaa..d015eec6 100644 --- a/client/src/helpers/constants.js +++ b/client/src/helpers/constants.js @@ -4,6 +4,7 @@ export const R_IPV4 = /^(?:(?:^|\.)(?:2(?:5[0-5]|[0-4]\d)|1?\d?\d)){4}$/; export const R_IPV6 = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/; export const R_CIDR = /^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/([0-9]|[1-2][0-9]|3[0-2]))$/; export const R_MAC = /^((([a-fA-F0-9][a-fA-F0-9]+[-]){5}|([a-fA-F0-9][a-fA-F0-9]+[:]){5})([a-fA-F0-9][a-fA-F0-9])$)|(^([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]+[.]){2}([a-fA-F0-9][a-fA-F0-9][a-fA-F0-9][a-fA-F0-9]))$/; +export const R_PATH_LAST_PART = /\/[^/]*$/; export const STATS_NAMES = { avg_processing_time: 'average_processing_time',