Skip to content

Commit

Permalink
feat(notifications-service): log errors in console when displaying er…
Browse files Browse the repository at this point in the history
…ror notifications
  • Loading branch information
tkohr committed Dec 11, 2024
1 parent af826c8 commit f8de49c
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 97 deletions.
28 changes: 16 additions & 12 deletions apps/metadata-editor/src/app/duplicate-record.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ export class DuplicateRecordResolver {
.openRecordForDuplication(route.paramMap.get('uuid'))
.pipe(
catchError((error) => {
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.loadError.title'
),
text: `${this.translateService.instant(
'editor.record.loadError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.loadError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.loadError.title'
),
text: `${this.translateService.instant(
'editor.record.loadError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.loadError.closeMessage'
),
},
undefined,
error
)
return EMPTY
})
)
Expand Down
28 changes: 16 additions & 12 deletions apps/metadata-editor/src/app/edit-record.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,22 @@ export class EditRecordResolver {
.openRecordForEdition(route.paramMap.get('uuid'))
.pipe(
catchError((error) => {
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.loadError.title'
),
text: `${this.translateService.instant(
'editor.record.loadError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.loadError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.loadError.title'
),
text: `${this.translateService.instant(
'editor.record.loadError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.loadError.closeMessage'
),
},
undefined,
error
)
return EMPTY
})
)
Expand Down
58 changes: 33 additions & 25 deletions apps/metadata-editor/src/app/edit/edit-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,32 +83,40 @@ export class EditPageComponent implements OnInit, OnDestroy {
this.subscription.add(
this.facade.saveError$.subscribe((error) => {
if (error instanceof PublicationVersionError) {
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.publishVersionError.title'
),
text: this.translateService.instant(
'editor.record.publishVersionError.body',
{ currentVersion: error.detectedApiVersion }
),
closeMessage: this.translateService.instant(
'editor.record.publishVersionError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.publishVersionError.title'
),
text: this.translateService.instant(
'editor.record.publishVersionError.body',
{ currentVersion: error.detectedApiVersion }
),
closeMessage: this.translateService.instant(
'editor.record.publishVersionError.closeMessage'
),
},
undefined,
error
)
} else {
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.publishError.title'
),
text: `${this.translateService.instant(
'editor.record.publishError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.publishError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.publishError.title'
),
text: `${this.translateService.instant(
'editor.record.publishError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.publishError.closeMessage'
),
},
undefined,
error
)
}
})
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ export class ImportRecordComponent {
'editor.record.importFromExternalFile.failure.body'
)} ${error.message ?? ''}`,
},
2500
2500,
error
)
this.isRecordImportInProgress = false
this.cdr.markForCheck()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,18 +137,22 @@ export class FormFieldOnlineLinkResourcesComponent {
private handleError(error: Error) {
this.uploadProgress = undefined
this.cd.detectChanges()
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.onlineResourceError.title'
),
text: `${this.translateService.instant(
'editor.record.onlineResourceError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.onlineResourceError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.onlineResourceError.title'
),
text: `${this.translateService.instant(
'editor.record.onlineResourceError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.onlineResourceError.closeMessage'
),
},
undefined,
error
)
}

private openEditDialog(resource: OnlineLinkResource, index: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,18 +192,22 @@ export class FormFieldOnlineResourcesComponent {

private handleError(error: Error) {
this.uploadProgress = undefined
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.onlineResourceError.title'
),
text: `${this.translateService.instant(
'editor.record.onlineResourceError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.onlineResourceError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.onlineResourceError.title'
),
text: `${this.translateService.instant(
'editor.record.onlineResourceError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.onlineResourceError.closeMessage'
),
},
undefined,
error
)
}

private openEditDialog(resource: OnlineNotLinkResource, index: number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,21 @@ export class FormFieldOverviewsComponent {
private handleError = (error: Error) => {
this.uploadProgress = undefined
this.cd.markForCheck()
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant('editor.record.resourceError.title'),
text: `${this.translateService.instant(
'editor.record.resourceError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.resourceError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.resourceError.title'
),
text: `${this.translateService.instant(
'editor.record.resourceError.body'
)} ${error.message}`,
closeMessage: this.translateService.instant(
'editor.record.resourceError.closeMessage'
),
},
undefined,
error
)
}
}
7 changes: 6 additions & 1 deletion libs/feature/notifications/src/lib/notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ type NotificationWithIdentity = NotificationContent & { id: number }
export class NotificationsService {
notifications$ = new BehaviorSubject<NotificationWithIdentity[]>([])

showNotification(content: NotificationContent, timeoutMs?: number) {
showNotification(
content: NotificationContent,
timeoutMs?: number,
error?: Error
) {
error && console.error(error)
const id = Math.floor(Math.random() * 1000000)
this.notifications$.next([...this.notifications$.value, { ...content, id }])
if (typeof timeoutMs === 'undefined') return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,22 @@ export class ResultsTableContainerComponent implements OnDestroy {
)
},
error: (error) => {
this.notificationsService.showNotification({
type: 'error',
title: this.translateService.instant(
'editor.record.deleteError.title'
),
text: `${this.translateService.instant(
'editor.record.deleteError.body'
)} ${error}`,
closeMessage: this.translateService.instant(
'editor.record.deleteError.closeMessage'
),
})
this.notificationsService.showNotification(
{
type: 'error',
title: this.translateService.instant(
'editor.record.deleteError.title'
),
text: `${this.translateService.instant(
'editor.record.deleteError.body'
)} ${error}`,
closeMessage: this.translateService.instant(
'editor.record.deleteError.closeMessage'
),
},
undefined,
error
)
},
})
)
Expand Down

0 comments on commit f8de49c

Please sign in to comment.