diff --git a/apps/portal/src/app/graphql/graphql.service.ts b/apps/portal/src/app/graphql/graphql.service.ts index ecdd06ec..4e0b2574 100644 --- a/apps/portal/src/app/graphql/graphql.service.ts +++ b/apps/portal/src/app/graphql/graphql.service.ts @@ -59,4 +59,16 @@ export class GraphqlService { fetchPolicy: 'network-only', }); } + + // eslint-disable-next-line class-methods-use-this + validateApolloErrors(response: ApolloQueryResult): void { + if (response.errors && response.errors.length > 0) { + const errorMessages = response.errors.map((err) => err.message).join('; '); + throw new Error(`GraphQL Formatted Error(s): ${errorMessages}`); + } + + if (response.error) { + throw new Error(`Apollo Error: ${response.error.message}`); + } + } } diff --git a/apps/portal/src/app/views/notifications/notifications.component.ts b/apps/portal/src/app/views/notifications/notifications.component.ts index 7ff44fc4..273438fa 100644 --- a/apps/portal/src/app/views/notifications/notifications.component.ts +++ b/apps/portal/src/app/views/notifications/notifications.component.ts @@ -403,7 +403,7 @@ export class NotificationsComponent implements OnInit { key: 'tst', severity: 'error', summary: 'Error', - detail: `There was an error while loading notifications. Reason: ${error.message}`, + detail: `There was an error while loading archived notifications. Reason: ${error.message}`, }); this.loading = false; return of(null); diff --git a/apps/portal/src/app/views/notifications/notifications.service.ts b/apps/portal/src/app/views/notifications/notifications.service.ts index 608b68ca..0651f5e0 100644 --- a/apps/portal/src/app/views/notifications/notifications.service.ts +++ b/apps/portal/src/app/views/notifications/notifications.service.ts @@ -32,6 +32,7 @@ export class NotificationsService { getNotifications(variables: unknown, inputToken: string): Observable { return this.graphqlService.query(GetNotifications, variables, inputToken).pipe( map((response: ApolloQueryResult) => { + this.graphqlService.validateApolloErrors(response); const notificationArray = response.data?.notifications.notifications; const notificationResponseObject: NotificationResponse = { @@ -52,6 +53,7 @@ export class NotificationsService { getArchivedNotifications(variables, inputToken): Observable { return this.graphqlService.query(GetArchivedNotifications, variables, inputToken).pipe( map((response: ApolloQueryResult) => { + this.graphqlService.validateApolloErrors(response); const archivedNotificationArray = response.data?.archivedNotifications.archivedNotifications; diff --git a/apps/portal/src/app/views/providers/providers.service.ts b/apps/portal/src/app/views/providers/providers.service.ts index fdefc531..50232ab2 100644 --- a/apps/portal/src/app/views/providers/providers.service.ts +++ b/apps/portal/src/app/views/providers/providers.service.ts @@ -55,6 +55,7 @@ export class ProvidersService { .query(GetProvidersAndArchivedNotifications, variables, inputToken) .pipe( map((response: ApolloQueryResult) => { + this.graphqlService.validateApolloErrors(response); const providerArray = response.data?.providers.providers; const archivedNotificationArray = response.data?.archivedNotifications.archivedNotifications; @@ -95,6 +96,7 @@ export class ProvidersService { return this.graphqlService.query(GetProvidersAndNotifications, variables, inputToken).pipe( map((response: ApolloQueryResult) => { + this.graphqlService.validateApolloErrors(response); const providerArray = response.data?.providers.providers; const notificationArray = response.data?.notifications.notifications;