From 772bf52e29f30fcb56c6b10d194e5fc610f44cba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adina=20=C8=9Aeudan?= Date: Wed, 9 Feb 2022 15:31:30 +0200 Subject: [PATCH] Improved error handling for missing types --- .../src/app/models/file/file-data.model.ts | 11 +++----- .../services/pdf-viewer-data.service.ts | 26 +++++++++---------- apps/red-ui/src/app/utils/constants.ts | 1 - apps/red-ui/src/assets/i18n/en.json | 2 +- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/apps/red-ui/src/app/models/file/file-data.model.ts b/apps/red-ui/src/app/models/file/file-data.model.ts index 581289732..dea3703f0 100644 --- a/apps/red-ui/src/app/models/file/file-data.model.ts +++ b/apps/red-ui/src/app/models/file/file-data.model.ts @@ -13,12 +13,12 @@ import { AnnotationWrapper } from './annotation.wrapper'; import * as moment from 'moment'; import { BehaviorSubject } from 'rxjs'; import { RedactionLogEntry } from './redaction-log.entry'; -import { MISSING_TYPES_ERROR } from '@utils/constants'; export class FileDataModel { static readonly DELTA_VIEW_TIME = 10 * 60 * 1000; // 10 minutes; allAnnotations: AnnotationWrapper[] = []; readonly hasChangeLog$ = new BehaviorSubject(false); + missingTypes = new Set(); constructor( private readonly _file: File, @@ -77,7 +77,6 @@ export class FileDataModel { private _convertData(): RedactionLogEntry[] { let result: RedactionLogEntry[] = []; - const missingTypes = new Set(); const reasonAnnotationIds: { [key: string]: RedactionLogEntry[] } = {}; this.redactionLog.redactionLogEntry?.forEach(redactionLogEntry => { @@ -85,7 +84,7 @@ export class FileDataModel { const changeLogValues = this.#getChangeLogValues(redactionLogEntry); if (!this._dictionaryData[redactionLogEntry.type]) { - missingTypes.add(redactionLogEntry.type); + this.missingTypes.add(redactionLogEntry.type); return; } @@ -95,7 +94,7 @@ export class FileDataModel { changeLogValues.isChangeLogEntry, changeLogValues.hidden, this.redactionLog.legalBasis, - this._dictionaryData[redactionLogEntry.type].hint, + !!this._dictionaryData[redactionLogEntry.type]?.hint, ); if ( @@ -130,10 +129,6 @@ export class FileDataModel { result = result.filter(r => !r.hidden); - if (missingTypes.size > 0) { - throw new Error(MISSING_TYPES_ERROR); - } - return result; } diff --git a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts index 70a8b48f2..ec3ec2a65 100644 --- a/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts +++ b/apps/red-ui/src/app/modules/dossier/services/pdf-viewer-data.service.ts @@ -10,7 +10,6 @@ import { AppStateService } from '@state/app-state.service'; import { UserPreferenceService } from '@services/user-preference.service'; import { FilePreviewStateService } from '../screens/file-preview-screen/services/file-preview-state.service'; import { Toaster } from '@iqser/common-ui'; -import { MISSING_TYPES_ERROR } from '@utils/constants'; import { marker as _ } from '@biesbjerg/ngx-translate-extract-marker'; @Injectable() @@ -38,20 +37,19 @@ export class PdfViewerDataService { return forkJoin([redactionLog$, viewedPages$]).pipe( map((data: [redactionLog: IRedactionLog, viewedPages: IViewedPage[]]) => { - try { - return new FileDataModel( - newFile, - ...data, - this._appStateService.dictionaryData[this._stateService.dossierTemplateId], - this._userPreferenceService.areDevFeaturesEnabled, - ); - } catch (error) { - if (error.message === MISSING_TYPES_ERROR) { - this._toaster.error(_('error.missing-types'), { disableTimeOut: true }); - } else { - throw error; - } + const fileDataModel = new FileDataModel( + newFile, + ...data, + this._appStateService.dictionaryData[this._stateService.dossierTemplateId], + this._userPreferenceService.areDevFeaturesEnabled, + ); + if (fileDataModel.missingTypes.size > 0) { + this._toaster.error(_('error.missing-types'), { + disableTimeOut: true, + params: { missingTypes: Array.from(fileDataModel.missingTypes).join(', ') }, + }); } + return fileDataModel; }), ); } diff --git a/apps/red-ui/src/app/utils/constants.ts b/apps/red-ui/src/app/utils/constants.ts index 5b70b1f9f..63ba0e493 100644 --- a/apps/red-ui/src/app/utils/constants.ts +++ b/apps/red-ui/src/app/utils/constants.ts @@ -1,2 +1 @@ export const CHANGED_CHECK_INTERVAL = 5000; -export const MISSING_TYPES_ERROR = 'MISSING_TYPES_ERROR'; diff --git a/apps/red-ui/src/assets/i18n/en.json b/apps/red-ui/src/assets/i18n/en.json index b62b6d63e..0e5a869f2 100644 --- a/apps/red-ui/src/assets/i18n/en.json +++ b/apps/red-ui/src/assets/i18n/en.json @@ -1000,7 +1000,7 @@ "http": { "generic": "Action failed with code {status}" }, - "missing-types": "The dossier template has missing types. Data might not be displayed correctly.", + "missing-types": "The dossier template has missing types ({missingTypes}). Data might not be displayed correctly.", "offline": "Disconnected", "online": "Reconnected", "reload": "Reload",