Remove errors when 401 unauthorized.

This commit is contained in:
Abhinav Jha 2020-04-15 19:49:39 +05:30
parent 431f20b8c4
commit f3cccd9aee
4 changed files with 20 additions and 6 deletions

View File

@ -8,6 +8,7 @@ import {
import { ActionApiResponse } from "./ActionAPI";
import { AUTH_LOGIN_URL } from "constants/routes";
import { setRouteBeforeLogin } from "utils/storage";
import history from "utils/history";
const { apiUrl, baseUrl } = getAppsmithConfigs();
//TODO(abhinav): Refactor this to make more composable.
@ -58,8 +59,12 @@ axiosInstance.interceptors.response.use(
// console.log(error.response.headers);
if (error.response.status === 401) {
setRouteBeforeLogin(window.location.pathname);
window.location.href = AUTH_LOGIN_URL;
return;
history.push(AUTH_LOGIN_URL);
return Promise.reject({
code: 401,
message: "Unauthorized. Redirecting to login page...",
show: false,
});
}
if (error.response.data.responseMeta) {
return Promise.resolve(error.response.data);

View File

@ -59,7 +59,7 @@ export function getResponseErrorMessage(response: ApiResponse) {
: undefined;
}
type ErrorPayloadType = { message?: string };
type ErrorPayloadType = { code?: number; message?: string };
let ActionErrorDisplayMap: {
[key: string]: (error: ErrorPayloadType) => string;
} = {};
@ -92,7 +92,12 @@ export function* errorSaga(
} = errorAction;
const message =
error && error.message ? error.message : ActionErrorDisplayMap[type](error);
if (show) AppToaster.show({ message, type: ToastType.ERROR });
if (show && error.code !== 401) {
// error.code !== 401 IS A HACK!
// TODO(abhinav): Figure out a generic way
AppToaster.show({ message, type: ToastType.ERROR });
}
yield put({
type: ReduxActionTypes.REPORT_ERROR,
payload: {

View File

@ -288,6 +288,10 @@ export function* fetchUserSaga(action: ReduxAction<FetchUserRequest>) {
return yield false;
} catch (error) {
console.log(error);
yield put({
type: ReduxActionErrorTypes.FETCH_USER_ERROR,
payload: error,
});
}
}

View File

@ -184,8 +184,8 @@ class AnalyticsUtil {
static reset() {
const windowDoc: any = window;
windowDoc.analytics.reset();
windowDoc.mixpanel.reset();
windowDoc.analytics && windowDoc.analytics.reset();
windowDoc.mixpanel && windowDoc.mixpanel.reset();
}
}