Skip to content

Commit

Permalink
Merge pull request #36248 from appsmithorg/cherrypick/rbac-errors
Browse files Browse the repository at this point in the history
chore: Cherry Pick RBAC error fix
  • Loading branch information
hetunandu committed Sep 11, 2024
2 parents 9c28b41 + 05adea7 commit 8525981
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
10 changes: 8 additions & 2 deletions app/client/src/sagas/ActionSagas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -795,13 +795,19 @@ function* copyActionSaga(

// @ts-expect-error: type mismatch Action vs ActionCreateUpdateResponse
yield put(copyActionSuccess(payload));
} catch (e) {
} catch (e: unknown) {
const actionName = actionObject ? actionObject.name : "";
const errorMessage =
e instanceof Error
? e.message
: createMessage(ERROR_ACTION_COPY_FAIL, actionName);
yield put(
copyActionError({
...action.payload,
show: true,
error: { message: createMessage(ERROR_ACTION_COPY_FAIL, actionName) },
error: {
message: errorMessage,
},
}),
);
}
Expand Down
27 changes: 17 additions & 10 deletions app/client/src/sagas/ErrorSagas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,16 @@ export function* validateResponse(
}

if (!response.responseMeta && response.status) {
throw Error(getErrorMessage(response.status, response.resourceType));
yield put({
type: ReduxActionErrorTypes.API_ERROR,
payload: {
error: new Error(
getErrorMessage(response.status, response.resourceType),
),
logToSentry,
show,
},
});
}

if (response.responseMeta.success) {
Expand Down Expand Up @@ -218,22 +227,20 @@ export interface ErrorActionPayload {
export function* errorSaga(errorAction: ReduxAction<ErrorActionPayload>) {
const effects = [ErrorEffectTypes.LOG_TO_CONSOLE];
const { payload, type } = errorAction;
const {
error,
logToDebugger,
logToSentry,
show = true,
sourceEntity,
} = payload || {};
const { error, logToDebugger, logToSentry, show, sourceEntity } =
payload || {};
const appMode: APP_MODE = yield select(getAppMode);

// "show" means show a toast. We check if the error has been asked to not been shown
// By making the default behaviour "true" we are ensuring undefined actions still pass through this check
if (show) {
// By checking undefined, undecided actions still pass through this check
if (show === undefined) {
// We want to show toasts for certain actions only so we avoid issues or if it is outside edit mode
if (shouldShowToast(type) || appMode !== APP_MODE.EDIT) {
effects.push(ErrorEffectTypes.SHOW_ALERT);
}
// If true is passed, show the error no matter what
} else if (show) {
effects.push(ErrorEffectTypes.SHOW_ALERT);
}

if (logToDebugger) {
Expand Down

0 comments on commit 8525981

Please sign in to comment.