Remove errors when 401 unauthorized.
This commit is contained in:
parent
431f20b8c4
commit
f3cccd9aee
|
|
@ -8,6 +8,7 @@ import {
|
||||||
import { ActionApiResponse } from "./ActionAPI";
|
import { ActionApiResponse } from "./ActionAPI";
|
||||||
import { AUTH_LOGIN_URL } from "constants/routes";
|
import { AUTH_LOGIN_URL } from "constants/routes";
|
||||||
import { setRouteBeforeLogin } from "utils/storage";
|
import { setRouteBeforeLogin } from "utils/storage";
|
||||||
|
import history from "utils/history";
|
||||||
const { apiUrl, baseUrl } = getAppsmithConfigs();
|
const { apiUrl, baseUrl } = getAppsmithConfigs();
|
||||||
|
|
||||||
//TODO(abhinav): Refactor this to make more composable.
|
//TODO(abhinav): Refactor this to make more composable.
|
||||||
|
|
@ -58,8 +59,12 @@ axiosInstance.interceptors.response.use(
|
||||||
// console.log(error.response.headers);
|
// console.log(error.response.headers);
|
||||||
if (error.response.status === 401) {
|
if (error.response.status === 401) {
|
||||||
setRouteBeforeLogin(window.location.pathname);
|
setRouteBeforeLogin(window.location.pathname);
|
||||||
window.location.href = AUTH_LOGIN_URL;
|
history.push(AUTH_LOGIN_URL);
|
||||||
return;
|
return Promise.reject({
|
||||||
|
code: 401,
|
||||||
|
message: "Unauthorized. Redirecting to login page...",
|
||||||
|
show: false,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if (error.response.data.responseMeta) {
|
if (error.response.data.responseMeta) {
|
||||||
return Promise.resolve(error.response.data);
|
return Promise.resolve(error.response.data);
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,7 @@ export function getResponseErrorMessage(response: ApiResponse) {
|
||||||
: undefined;
|
: undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
type ErrorPayloadType = { message?: string };
|
type ErrorPayloadType = { code?: number; message?: string };
|
||||||
let ActionErrorDisplayMap: {
|
let ActionErrorDisplayMap: {
|
||||||
[key: string]: (error: ErrorPayloadType) => string;
|
[key: string]: (error: ErrorPayloadType) => string;
|
||||||
} = {};
|
} = {};
|
||||||
|
|
@ -92,7 +92,12 @@ export function* errorSaga(
|
||||||
} = errorAction;
|
} = errorAction;
|
||||||
const message =
|
const message =
|
||||||
error && error.message ? error.message : ActionErrorDisplayMap[type](error);
|
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({
|
yield put({
|
||||||
type: ReduxActionTypes.REPORT_ERROR,
|
type: ReduxActionTypes.REPORT_ERROR,
|
||||||
payload: {
|
payload: {
|
||||||
|
|
|
||||||
|
|
@ -288,6 +288,10 @@ export function* fetchUserSaga(action: ReduxAction<FetchUserRequest>) {
|
||||||
return yield false;
|
return yield false;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
|
yield put({
|
||||||
|
type: ReduxActionErrorTypes.FETCH_USER_ERROR,
|
||||||
|
payload: error,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -184,8 +184,8 @@ class AnalyticsUtil {
|
||||||
|
|
||||||
static reset() {
|
static reset() {
|
||||||
const windowDoc: any = window;
|
const windowDoc: any = window;
|
||||||
windowDoc.analytics.reset();
|
windowDoc.analytics && windowDoc.analytics.reset();
|
||||||
windowDoc.mixpanel.reset();
|
windowDoc.mixpanel && windowDoc.mixpanel.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user