Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create common graphql error handler #384

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions apps/portal/src/app/graphql/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,16 @@ export class GraphqlService {
fetchPolicy: 'network-only',
});
}

// eslint-disable-next-line class-methods-use-this
validateApolloErrors<T>(response: ApolloQueryResult<T>): 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}`);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class NotificationsService {
getNotifications(variables: unknown, inputToken: string): Observable<NotificationResponse> {
return this.graphqlService.query(GetNotifications, variables, inputToken).pipe(
map((response: ApolloQueryResult<GetNotificationsResponse>) => {
this.graphqlService.validateApolloErrors(response);
const notificationArray = response.data?.notifications.notifications;

const notificationResponseObject: NotificationResponse = {
Expand All @@ -52,6 +53,7 @@ export class NotificationsService {
getArchivedNotifications(variables, inputToken): Observable<NotificationResponse> {
return this.graphqlService.query(GetArchivedNotifications, variables, inputToken).pipe(
map((response: ApolloQueryResult<GetArchivedNotificationsResponse>) => {
this.graphqlService.validateApolloErrors(response);
const archivedNotificationArray =
response.data?.archivedNotifications.archivedNotifications;

Expand Down
2 changes: 2 additions & 0 deletions apps/portal/src/app/views/providers/providers.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class ProvidersService {
.query(GetProvidersAndArchivedNotifications, variables, inputToken)
.pipe(
map((response: ApolloQueryResult<GetProviderArchivedNotificationResponse>) => {
this.graphqlService.validateApolloErrors(response);
const providerArray = response.data?.providers.providers;
const archivedNotificationArray =
response.data?.archivedNotifications.archivedNotifications;
Expand Down Expand Up @@ -95,6 +96,7 @@ export class ProvidersService {

return this.graphqlService.query(GetProvidersAndNotifications, variables, inputToken).pipe(
map((response: ApolloQueryResult<GetProviderNotificationResponse>) => {
this.graphqlService.validateApolloErrors(response);
const providerArray = response.data?.providers.providers;
const notificationArray = response.data?.notifications.notifications;

Expand Down
Loading