mirror of
https://github.com/apache/nifi.git
synced 2025-02-06 01:58:32 +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 {
|
||||
constructor(private nifiCommon: NiFiCommon) {}
|
||||
|
||||
fullScreenError(errorResponse: HttpErrorResponse): Action {
|
||||
fullScreenError(errorResponse: HttpErrorResponse, skipReplaceUrl?: boolean): Action {
|
||||
let title: string;
|
||||
let message: string;
|
||||
|
||||
@ -56,6 +56,7 @@ export class ErrorHelper {
|
||||
}
|
||||
|
||||
return ErrorActions.fullScreenError({
|
||||
skipReplaceUrl,
|
||||
errorDetail: {
|
||||
title,
|
||||
message
|
||||
|
@ -21,6 +21,7 @@ import { map } from 'rxjs';
|
||||
import { Store } from '@ngrx/store';
|
||||
import { CurrentUser, CurrentUserState } from '../../state/current-user';
|
||||
import { selectCurrentUser } from '../../state/current-user/current-user.selectors';
|
||||
import { fullScreenError } from '../../state/error/error.actions';
|
||||
|
||||
export const authorizationGuard = (
|
||||
authorizationCheck: (user: CurrentUser) => boolean,
|
||||
@ -36,8 +37,20 @@ export const authorizationGuard = (
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO - replace with 403 error page
|
||||
return router.parseUrl(fallbackUrl || '/');
|
||||
if (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.
|
||||
*/
|
||||
|
||||
import { CanMatchFn, Router } from '@angular/router';
|
||||
import { CanMatchFn } from '@angular/router';
|
||||
import { inject } from '@angular/core';
|
||||
import { catchError, map, of, switchMap, tap } from 'rxjs';
|
||||
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 { FlowConfigurationService } from '../flow-configuration.service';
|
||||
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 = (
|
||||
flowConfigurationCheck: (flowConfiguration: FlowConfiguration) => boolean
|
||||
): CanMatchFn => {
|
||||
return () => {
|
||||
const router: Router = inject(Router);
|
||||
const store: Store<FlowConfigurationState> = inject(Store<FlowConfigurationState>);
|
||||
const flowConfigurationService: FlowConfigurationService = inject(FlowConfigurationService);
|
||||
const errorHelper: ErrorHelper = inject(ErrorHelper);
|
||||
|
||||
return store.select(selectFlowConfiguration).pipe(
|
||||
switchMap((flowConfiguration) => {
|
||||
@ -53,12 +56,20 @@ export const checkFlowConfiguration = (
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO - replace with error page
|
||||
return router.parseUrl('/');
|
||||
store.dispatch(
|
||||
fullScreenError({
|
||||
skipReplaceUrl: true,
|
||||
errorDetail: {
|
||||
title: 'Unable to load',
|
||||
message: 'Flow configuration check failed'
|
||||
}
|
||||
})
|
||||
);
|
||||
return false;
|
||||
}),
|
||||
catchError(() => {
|
||||
// TODO - replace with error page
|
||||
return of(router.parseUrl('/'));
|
||||
catchError((errorResponse: HttpErrorResponse) => {
|
||||
store.dispatch(errorHelper.fullScreenError(errorResponse, true));
|
||||
return of(false);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
@ -18,7 +18,10 @@
|
||||
import { createAction, props } from '@ngrx/store';
|
||||
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 }>());
|
||||
|
||||
|
@ -36,9 +36,15 @@ export class ErrorEffects {
|
||||
() =>
|
||||
this.actions$.pipe(
|
||||
ofType(ErrorActions.fullScreenError),
|
||||
tap(() => {
|
||||
map((action) => action.skipReplaceUrl),
|
||||
tap((skipReplaceUrl) => {
|
||||
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 }
|
||||
|
Loading…
x
Reference in New Issue
Block a user