Remove errors when 401 unauthorized.
This commit is contained in:
parent
431f20b8c4
commit
f3cccd9aee
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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: {
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user