mirror of
https://github.com/apache/nifi.git
synced 2025-02-06 10:08:42 +00:00
NIFI-13140: (#8743)
- Cleaning up error handling in guards. This closes #8743
This commit is contained in:
parent
3192bc85ef
commit
ab5025c652
@ -25,7 +25,7 @@ import { NiFiCommon } from './nifi-common.service';
|
|||||||
export class ErrorHelper {
|
export class ErrorHelper {
|
||||||
constructor(private nifiCommon: NiFiCommon) {}
|
constructor(private nifiCommon: NiFiCommon) {}
|
||||||
|
|
||||||
fullScreenError(errorResponse: HttpErrorResponse): Action {
|
fullScreenError(errorResponse: HttpErrorResponse, skipReplaceUrl?: boolean): Action {
|
||||||
let title: string;
|
let title: string;
|
||||||
let message: string;
|
let message: string;
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ export class ErrorHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return ErrorActions.fullScreenError({
|
return ErrorActions.fullScreenError({
|
||||||
|
skipReplaceUrl,
|
||||||
errorDetail: {
|
errorDetail: {
|
||||||
title,
|
title,
|
||||||
message
|
message
|
||||||
|
@ -21,6 +21,7 @@ import { map } from 'rxjs';
|
|||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { CurrentUser, CurrentUserState } from '../../state/current-user';
|
import { CurrentUser, CurrentUserState } from '../../state/current-user';
|
||||||
import { selectCurrentUser } from '../../state/current-user/current-user.selectors';
|
import { selectCurrentUser } from '../../state/current-user/current-user.selectors';
|
||||||
|
import { fullScreenError } from '../../state/error/error.actions';
|
||||||
|
|
||||||
export const authorizationGuard = (
|
export const authorizationGuard = (
|
||||||
authorizationCheck: (user: CurrentUser) => boolean,
|
authorizationCheck: (user: CurrentUser) => boolean,
|
||||||
@ -36,8 +37,20 @@ export const authorizationGuard = (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - replace with 403 error page
|
if (fallbackUrl) {
|
||||||
return router.parseUrl(fallbackUrl || '/');
|
return router.parseUrl(fallbackUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
store.dispatch(
|
||||||
|
fullScreenError({
|
||||||
|
skipReplaceUrl: true,
|
||||||
|
errorDetail: {
|
||||||
|
title: 'Unable to load',
|
||||||
|
message: 'Authorization check failed. Contact the system administrator.'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return false;
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CanMatchFn, Router } from '@angular/router';
|
import { CanMatchFn } from '@angular/router';
|
||||||
import { inject } from '@angular/core';
|
import { inject } from '@angular/core';
|
||||||
import { catchError, map, of, switchMap, tap } from 'rxjs';
|
import { catchError, map, of, switchMap, tap } from 'rxjs';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
@ -23,14 +23,17 @@ import { FlowConfiguration, FlowConfigurationState } from '../../state/flow-conf
|
|||||||
import { selectFlowConfiguration } from '../../state/flow-configuration/flow-configuration.selectors';
|
import { selectFlowConfiguration } from '../../state/flow-configuration/flow-configuration.selectors';
|
||||||
import { FlowConfigurationService } from '../flow-configuration.service';
|
import { FlowConfigurationService } from '../flow-configuration.service';
|
||||||
import { loadFlowConfigurationSuccess } from '../../state/flow-configuration/flow-configuration.actions';
|
import { loadFlowConfigurationSuccess } from '../../state/flow-configuration/flow-configuration.actions';
|
||||||
|
import { fullScreenError } from '../../state/error/error.actions';
|
||||||
|
import { HttpErrorResponse } from '@angular/common/http';
|
||||||
|
import { ErrorHelper } from '../error-helper.service';
|
||||||
|
|
||||||
export const checkFlowConfiguration = (
|
export const checkFlowConfiguration = (
|
||||||
flowConfigurationCheck: (flowConfiguration: FlowConfiguration) => boolean
|
flowConfigurationCheck: (flowConfiguration: FlowConfiguration) => boolean
|
||||||
): CanMatchFn => {
|
): CanMatchFn => {
|
||||||
return () => {
|
return () => {
|
||||||
const router: Router = inject(Router);
|
|
||||||
const store: Store<FlowConfigurationState> = inject(Store<FlowConfigurationState>);
|
const store: Store<FlowConfigurationState> = inject(Store<FlowConfigurationState>);
|
||||||
const flowConfigurationService: FlowConfigurationService = inject(FlowConfigurationService);
|
const flowConfigurationService: FlowConfigurationService = inject(FlowConfigurationService);
|
||||||
|
const errorHelper: ErrorHelper = inject(ErrorHelper);
|
||||||
|
|
||||||
return store.select(selectFlowConfiguration).pipe(
|
return store.select(selectFlowConfiguration).pipe(
|
||||||
switchMap((flowConfiguration) => {
|
switchMap((flowConfiguration) => {
|
||||||
@ -53,12 +56,20 @@ export const checkFlowConfiguration = (
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO - replace with error page
|
store.dispatch(
|
||||||
return router.parseUrl('/');
|
fullScreenError({
|
||||||
|
skipReplaceUrl: true,
|
||||||
|
errorDetail: {
|
||||||
|
title: 'Unable to load',
|
||||||
|
message: 'Flow configuration check failed'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
return false;
|
||||||
}),
|
}),
|
||||||
catchError(() => {
|
catchError((errorResponse: HttpErrorResponse) => {
|
||||||
// TODO - replace with error page
|
store.dispatch(errorHelper.fullScreenError(errorResponse, true));
|
||||||
return of(router.parseUrl('/'));
|
return of(false);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,10 @@
|
|||||||
import { createAction, props } from '@ngrx/store';
|
import { createAction, props } from '@ngrx/store';
|
||||||
import { ErrorDetail } from './index';
|
import { ErrorDetail } from './index';
|
||||||
|
|
||||||
export const fullScreenError = createAction('[Error] Full Screen Error', props<{ errorDetail: ErrorDetail }>());
|
export const fullScreenError = createAction(
|
||||||
|
'[Error] Full Screen Error',
|
||||||
|
props<{ errorDetail: ErrorDetail; skipReplaceUrl?: boolean }>()
|
||||||
|
);
|
||||||
|
|
||||||
export const snackBarError = createAction('[Error] Snackbar Error', props<{ error: string }>());
|
export const snackBarError = createAction('[Error] Snackbar Error', props<{ error: string }>());
|
||||||
|
|
||||||
|
@ -36,9 +36,15 @@ export class ErrorEffects {
|
|||||||
() =>
|
() =>
|
||||||
this.actions$.pipe(
|
this.actions$.pipe(
|
||||||
ofType(ErrorActions.fullScreenError),
|
ofType(ErrorActions.fullScreenError),
|
||||||
tap(() => {
|
map((action) => action.skipReplaceUrl),
|
||||||
|
tap((skipReplaceUrl) => {
|
||||||
this.dialog.openDialogs.forEach((dialog) => dialog.close('ROUTED'));
|
this.dialog.openDialogs.forEach((dialog) => dialog.close('ROUTED'));
|
||||||
this.router.navigate(['/error'], { replaceUrl: true });
|
|
||||||
|
if (skipReplaceUrl) {
|
||||||
|
this.router.navigate(['/error']);
|
||||||
|
} else {
|
||||||
|
this.router.navigate(['/error'], { replaceUrl: true });
|
||||||
|
}
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
{ dispatch: false }
|
{ dispatch: false }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user