Improved error handling for missing types

This commit is contained in:
Adina Țeudan 2022-02-09 15:31:30 +02:00
parent 15a5b5c339
commit 772bf52e29
4 changed files with 16 additions and 24 deletions

View File

@ -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<boolean>(false);
missingTypes = new Set<string>();
constructor(
private readonly _file: File,
@ -77,7 +77,6 @@ export class FileDataModel {
private _convertData(): RedactionLogEntry[] {
let result: RedactionLogEntry[] = [];
const missingTypes = new Set<string>();
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;
}

View File

@ -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;
}),
);
}

View File

@ -1,2 +1 @@
export const CHANGED_CHECK_INTERVAL = 5000;
export const MISSING_TYPES_ERROR = 'MISSING_TYPES_ERROR';

View File

@ -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",