Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Updating error handling in Global and Component Policy pages.
  • Loading branch information
mcgilman committed Apr 25, 2024
1 parent 7bb6eeb commit c437f9d
Show file tree
Hide file tree
Showing 16 changed files with 65 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ export const resetAccessPolicy = createAction(
props<{ response: ResetAccessPolicy }>()
);

export const accessPolicyApiError = createAction(
`${ACCESS_POLICY_PREFIX} Access Policy Api Error`,
export const accessPolicyApiBannerError = createAction(
`${ACCESS_POLICY_PREFIX} Access Policy Api Banner Error`,
props<{ response: LoadAccessPolicyError }>()
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { NiFiState } from '../../../../state';
import { Store } from '@ngrx/store';
import { Router } from '@angular/router';
import * as AccessPolicyActions from './access-policy.actions';
import * as ErrorActions from '../../../../state/error/error.actions';
import { catchError, from, map, of, switchMap, take, tap } from 'rxjs';
import { MatDialog } from '@angular/material/dialog';
import { AccessPolicyService } from '../../service/access-policy.service';
Expand All @@ -34,6 +35,7 @@ import { AddTenantsToPolicyRequest } from './index';
import { selectUserGroups, selectUsers } from '../tenants/tenants.selectors';
import { OverridePolicyDialog } from '../../ui/common/override-policy-dialog/override-policy-dialog.component';
import { MEDIUM_DIALOG, SMALL_DIALOG } from '../../../../index';
import { HttpErrorResponse } from '@angular/common/http';

@Injectable()
export class AccessPolicyEffects {
Expand Down Expand Up @@ -105,11 +107,11 @@ export class AccessPolicyEffects {
}
});
}),
catchError((error) => {
catchError((errorResponse: HttpErrorResponse) => {
let policyStatus: PolicyStatus | undefined;
if (error.status === 404) {
if (errorResponse.status === 404) {
policyStatus = PolicyStatus.NotFound;
} else if (error.status === 403) {
} else if (errorResponse.status === 403) {
policyStatus = PolicyStatus.Forbidden;
}

Expand All @@ -123,9 +125,9 @@ export class AccessPolicyEffects {
);
} else {
return of(
AccessPolicyActions.accessPolicyApiError({
AccessPolicyActions.accessPolicyApiBannerError({
response: {
error: error.error
error: errorResponse.error
}
})
);
Expand Down Expand Up @@ -153,11 +155,11 @@ export class AccessPolicyEffects {
}
});
}),
catchError((error) =>
catchError((errorResponse: HttpErrorResponse) =>
of(
AccessPolicyActions.accessPolicyApiError({
AccessPolicyActions.accessPolicyApiBannerError({
response: {
error: error.error
error: errorResponse.error
}
})
)
Expand Down Expand Up @@ -227,11 +229,11 @@ export class AccessPolicyEffects {
}
});
}),
catchError((error) =>
catchError((errorResponse: HttpErrorResponse) =>
of(
AccessPolicyActions.accessPolicyApiError({
AccessPolicyActions.accessPolicyApiBannerError({
response: {
error: error.error
error: errorResponse.error
}
})
)
Expand Down Expand Up @@ -331,11 +333,11 @@ export class AccessPolicyEffects {
}
});
}),
catchError((error) =>
catchError((errorResponse: HttpErrorResponse) =>
of(
AccessPolicyActions.accessPolicyApiError({
AccessPolicyActions.accessPolicyApiBannerError({
response: {
error: error.error
error: errorResponse.error
}
})
)
Expand Down Expand Up @@ -401,11 +403,11 @@ export class AccessPolicyEffects {
}
});
}),
catchError((error) =>
catchError((errorResponse: HttpErrorResponse) =>
of(
AccessPolicyActions.accessPolicyApiError({
AccessPolicyActions.accessPolicyApiBannerError({
response: {
error: error.error
error: errorResponse.error
}
})
)
Expand Down Expand Up @@ -455,11 +457,11 @@ export class AccessPolicyEffects {
}
});
}),
catchError((error) =>
catchError((errorResponse: HttpErrorResponse) =>
of(
AccessPolicyActions.accessPolicyApiError({
AccessPolicyActions.accessPolicyApiBannerError({
response: {
error: error.error
error: errorResponse.error
}
})
)
Expand All @@ -468,4 +470,13 @@ export class AccessPolicyEffects {
)
)
);

accessPolicyApiBannerError$ = createEffect(() =>
this.actions$.pipe(
ofType(AccessPolicyActions.accessPolicyApiBannerError),
map((action) => action.response),
tap(() => this.dialog.closeAll()),
switchMap((response) => of(ErrorActions.addBannerError({ error: response.error })))
)
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { createReducer, on } from '@ngrx/store';
import {
addTenantsToPolicy,
createAccessPolicySuccess,
accessPolicyApiError,
accessPolicyApiBannerError,
loadAccessPolicy,
loadAccessPolicySuccess,
removeTenantFromPolicy,
Expand All @@ -32,7 +32,6 @@ import {
export const initialState: AccessPolicyState = {
saving: false,
loadedTimestamp: '',
error: null,
status: 'pending'
};

Expand Down Expand Up @@ -69,11 +68,10 @@ export const accessPolicyReducer = createReducer(
loadedTimestamp: 'N/A',
status: 'success' as const
})),
on(accessPolicyApiError, (state, { response }) => ({
on(accessPolicyApiBannerError, (state) => ({
...state,
error: response.error,
accessPolicy: undefined,
policyStatus: undefined,
loadedTimestamp: state.loadedTimestamp == initialState.loadedTimestamp ? 'N/A' : state.loadedTimestamp,
saving: false,
status: 'error' as const
})),
on(resetAccessPolicyState, () => ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,5 @@ export interface AccessPolicyState {
accessPolicy?: AccessPolicyEntity;
saving: boolean;
loadedTimestamp: string;
error: string | null;
status: 'pending' | 'loading' | 'error' | 'success';
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ export interface PolicyComponentState {
allowRemoteAccess: boolean;
resource: string;
loadedTimestamp: string;
error: string | null;
status: 'pending' | 'loading' | 'error' | 'success';
status: 'pending' | 'loading' | 'success';
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,4 @@ export const loadPolicyComponentSuccess = createAction(
props<{ response: LoadPolicyComponentSuccess }>()
);

export const policyComponentApiError = createAction(
`${POLICY_COMPONENT_PREFIX} Policy Component Api Error`,
props<{ error: string }>()
);

export const resetPolicyComponentState = createAction(`${POLICY_COMPONENT_PREFIX} Reset Policy Component State`);
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import * as PolicyComponentActions from './policy-component.actions';
import * as ErrorActions from '../../../../state/error/error.actions';
import { catchError, from, map, of, switchMap } from 'rxjs';
import { AccessPolicyService } from '../../service/access-policy.service';
import { HttpErrorResponse } from '@angular/common/http';

@Injectable()
export class PolicyComponentEffects {
Expand Down Expand Up @@ -47,8 +49,8 @@ export class PolicyComponentEffects {
}
})
),
catchError((error) => {
if (error.status === 403) {
catchError((errorResponse: HttpErrorResponse) => {
if (errorResponse.status === 403) {
return of(
PolicyComponentActions.loadPolicyComponentSuccess({
response: {
Expand All @@ -60,8 +62,8 @@ export class PolicyComponentEffects {
);
} else {
return of(
PolicyComponentActions.policyComponentApiError({
error: error.error
ErrorActions.snackBarError({
error: errorResponse.error
})
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,13 @@

import { PolicyComponentState } from './index';
import { createReducer, on } from '@ngrx/store';
import {
loadPolicyComponent,
loadPolicyComponentSuccess,
resetPolicyComponentState,
policyComponentApiError
} from './policy-component.actions';
import { loadPolicyComponent, loadPolicyComponentSuccess, resetPolicyComponentState } from './policy-component.actions';

export const initialState: PolicyComponentState = {
label: '',
resource: '',
allowRemoteAccess: false,
loadedTimestamp: '',
error: null,
status: 'pending'
};

Expand All @@ -46,11 +40,6 @@ export const policyComponentReducer = createReducer(
allowRemoteAccess: response.allowRemoteAccess,
status: 'success' as const
})),
on(policyComponentApiError, (state, { error }) => ({
...state,
error: error,
status: 'error' as const
})),
on(resetPolicyComponentState, () => ({
...initialState
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,5 @@ export interface TenantsState {
users: UserEntity[];
userGroups: UserGroupEntity[];
loadedTimestamp: string;
error: string | null;
status: 'pending' | 'loading' | 'error' | 'success';
status: 'pending' | 'loading' | 'success';
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,4 @@ export const loadTenantsSuccess = createAction(
props<{ response: LoadTenantsSuccess }>()
);

export const tenantsApiError = createAction(`${TENANTS_PREFIX} Tenants Api Error`, props<{ error: string }>());

export const resetTenantsState = createAction(`${TENANTS_PREFIX} Reset Tenants State`);
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@
import { Injectable } from '@angular/core';
import { Actions, createEffect, ofType } from '@ngrx/effects';
import * as TenantsActions from './tenants.actions';
import * as ErrorActions from '../../../../state/error/error.actions';
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
import { AccessPolicyService } from '../../service/access-policy.service';
import { HttpErrorResponse } from '@angular/common/http';

@Injectable()
export class TenantsEffects {
Expand All @@ -41,10 +43,10 @@ export class TenantsEffects {
}
})
),
catchError((error) =>
catchError((errorResponse: HttpErrorResponse) =>
of(
TenantsActions.tenantsApiError({
error: error.error
ErrorActions.snackBarError({
error: errorResponse.error
})
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,12 @@

import { TenantsState } from './index';
import { createReducer, on } from '@ngrx/store';
import { loadTenants, loadTenantsSuccess, resetTenantsState, tenantsApiError } from './tenants.actions';
import { loadTenants, loadTenantsSuccess, resetTenantsState } from './tenants.actions';

export const initialState: TenantsState = {
users: [],
userGroups: [],
loadedTimestamp: '',
error: null,
status: 'pending'
};

Expand All @@ -39,11 +38,6 @@ export const tenantsReducer = createReducer(
userGroups: response.userGroups,
status: 'success' as const
})),
on(tenantsApiError, (state, { error }) => ({
...state,
error: error,
status: 'error' as const
})),
on(resetTenantsState, () => ({
...initialState
}))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@if (policyComponentState$ | async; as policyComponentState) {
@if (flowConfiguration$ | async; as flowConfiguration) {
<div class="component-access-policies flex flex-col h-full gap-y-2">
<error-banner></error-banner>
<div class="accent-color font-medium">
<div class="mb-2">
@switch (accessPolicyState.policyStatus) {
Expand Down Expand Up @@ -61,7 +62,11 @@
</div>
<div class="flex flex-col">
<div class="operation-context-name">
{{ policyComponentState.label }}
{{
policyComponentState.label
? policyComponentState.label
: resourceIdentifier
}}
</div>
<div class="operation-context-type primary-color">
{{ getContextType() }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ComponentAccessPoliciesRoutingModule } from './component-access-policie
import { NifiTooltipDirective } from '../../../../ui/common/tooltips/nifi-tooltip.directive';
import { PolicyTable } from '../common/policy-table/policy-table.component';
import { MatButtonModule } from '@angular/material/button';
import { ErrorBanner } from '../../../../ui/common/error-banner/error-banner.component';

@NgModule({
declarations: [ComponentAccessPolicies],
Expand All @@ -43,7 +44,8 @@ import { MatButtonModule } from '@angular/material/button';
MatSelectModule,
NifiTooltipDirective,
PolicyTable,
MatButtonModule
MatButtonModule,
ErrorBanner
]
})
export class ComponentAccessPoliciesModule {}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
} @else {
@if (flowConfiguration$ | async; as flowConfiguration) {
<div class="global-access-policies flex flex-col h-full gap-y-2">
<error-banner></error-banner>
<div class="accent-color font-medium">
<div class="mb-2">
@switch (accessPolicyState.policyStatus) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { GlobalAccessPoliciesRoutingModule } from './global-access-policies-rout
import { NifiTooltipDirective } from '../../../../ui/common/tooltips/nifi-tooltip.directive';
import { PolicyTable } from '../common/policy-table/policy-table.component';
import { MatButtonModule } from '@angular/material/button';
import { ErrorBanner } from '../../../../ui/common/error-banner/error-banner.component';

@NgModule({
declarations: [GlobalAccessPolicies],
Expand All @@ -43,7 +44,8 @@ import { MatButtonModule } from '@angular/material/button';
MatSelectModule,
NifiTooltipDirective,
PolicyTable,
MatButtonModule
MatButtonModule,
ErrorBanner
]
})
export class GlobalAccessPoliciesModule {}

0 comments on commit c437f9d

Please sign in to comment.