Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add handleErrors options to suppress toast in ian-bell (#11972)

Oliver Güntherb18cb37a5b9d
diff --git a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
index 77384015ba8..a78f7ba0758 100644
--- a/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
+++ b/frontend/src/app/core/state/in-app-notifications/in-app-notifications.service.ts
@@ -6,17 +6,11 @@ import {
markNotificationsAsRead,
notificationsMarkedRead,
} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
-import {
- EffectCallback,
- EffectHandler,
-} from 'core-app/core/state/effects/effect-handler.decorator';
+import { EffectCallback, EffectHandler } from 'core-app/core/state/effects/effect-handler.decorator';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
import { InAppNotificationsStore } from './in-app-notifications.store';
import { INotification } from './in-app-notification.model';
-import {
- CollectionStore,
- ResourceCollectionService,
-} from 'core-app/core/state/resource-collection.service';
+import { CollectionStore, ResourceCollectionService } from 'core-app/core/state/resource-collection.service';
import { InjectField } from 'core-app/shared/helpers/angular/inject-field.decorator';
@EffectHandler
diff --git a/frontend/src/app/core/state/resource-collection.service.ts b/frontend/src/app/core/state/resource-collection.service.ts
index 5cdfbbe7063..bed76c81059 100644
--- a/frontend/src/app/core/state/resource-collection.service.ts
+++ b/frontend/src/app/core/state/resource-collection.service.ts
@@ -65,6 +65,10 @@ import { ToastService } from 'core-app/shared/components/toaster/toast.service';
export type CollectionStore<T> = EntityStore<CollectionState<T>>;
+export interface ResourceCollectionLoadOptions {
+ handleErrors:boolean;
+}
+
@Injectable()
export abstract class ResourceCollectionService<T extends { id:ID }> {
protected store:CollectionStore<T> = this.createStore();
@@ -225,8 +229,14 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {
/**
* Fetch a given collection, ensuring it is being flagged as loaded
+ *
+ * @param params {ApiV3ListParameters|string} collection key or list params to build collection key from
+ * @param options {ResourceCollectionLoadOptions} Handle collection loading errors within the resource service
*/
- fetchCollection(params:ApiV3ListParameters|string):Observable<IHALCollection<T>> {
+ fetchCollection(
+ params:ApiV3ListParameters|string,
+ options:ResourceCollectionLoadOptions = { handleErrors: true },
+ ):Observable<IHALCollection<T>> {
const key = typeof params === 'string' ? params : collectionKey(params);
setCollectionLoading(this.store, key);
@@ -238,7 +248,10 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {
tap((collection) => insertCollectionIntoState(this.store, collection, key)),
finalize(() => removeCollectionLoading(this.store, key)),
catchError((error:unknown) => {
- this.handleCollectionLoadingError(error as HttpErrorResponse, key);
+ if (options.handleErrors) {
+ this.handleCollectionLoadingError(error as HttpErrorResponse, key);
+ }
+
throw error;
}),
);
@@ -256,6 +269,12 @@ export abstract class ResourceCollectionService<T extends { id:ID }> {
*/
protected abstract basePath():string;
+ /**
+ * By default, add a toast error in case of loading errors
+ * @param error
+ * @param _collectionKey
+ * @protected
+ */
protected handleCollectionLoadingError(error:HttpErrorResponse, _collectionKey:string):void {
this.toastService.addError(error);
}
diff --git a/frontend/src/app/features/hal/resources/error-resource.ts b/frontend/src/app/features/hal/resources/error-resource.ts
index 92555e95a12..fe52f6c8317 100644
--- a/frontend/src/app/features/hal/resources/error-resource.ts
+++ b/frontend/src/app/features/hal/resources/error-resource.ts
@@ -38,9 +38,10 @@ export interface IHalErrorBase {
errorIdentifier:string;
}
-// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types,@typescript-eslint/no-explicit-any
-export function isHalError(err:any):err is IHalErrorBase {
- return '_type' in err && 'message' in err && 'errorIdentifier' in err;
+export function isHalError(err:unknown):err is IHalErrorBase {
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
+ const hasOwn = (key:string):boolean => Object.prototype.hasOwnProperty.call(err, key);
+ return !!err && hasOwn('_type') && hasOwn('message') && hasOwn('errorIdentifier');
}
export interface IHalSingleError extends IHalErrorBase {
diff --git a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
index 1f2148b30ee..b86d55793b6 100644
--- a/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
+++ b/frontend/src/app/features/in-app-notifications/bell/state/ian-bell.service.ts
@@ -1,6 +1,8 @@
import { Injectable } from '@angular/core';
import { IanBellStore } from './ian-bell.store';
-import { InAppNotificationsResourceService } from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
+import {
+ InAppNotificationsResourceService,
+} from 'core-app/core/state/in-app-notifications/in-app-notifications.service';
import { IAN_FACET_FILTERS } from 'core-app/features/in-app-notifications/center/state/ian-center.store';
import {
map,
@@ -17,7 +19,10 @@ import {
EffectCallback,
EffectHandler,
} from 'core-app/core/state/effects/effect-handler.decorator';
-import { notificationsMarkedRead, notificationCountIncreased } from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
+import {
+ notificationsMarkedRead,
+ notificationCountIncreased,
+} from 'core-app/core/state/in-app-notifications/in-app-notifications.actions';
import { ActionsService } from 'core-app/core/state/actions/actions.service';
/**
@@ -48,7 +53,10 @@ export class IanBellService {
fetchUnread():Observable<number> {
return this
.resourceService
- .fetchCollection({ filters: IAN_FACET_FILTERS.unread, pageSize: 0 })
+ .fetchCollection(
+ { filters: IAN_FACET_FILTERS.unread, pageSize: 0 },
+ { handleErrors: false },
+ )
.pipe(
map((result) => result.total),
tap(