From bf1643463d9a31d3b86c17b0d8345c3d14c33aef Mon Sep 17 00:00:00 2001 From: Quentin Ligier Date: Fri, 5 Jan 2024 09:56:31 +0100 Subject: [PATCH] Fix error handling in 'IGs' page --- .../src/app/igs/igs.component.html | 2 +- .../src/app/igs/igs.component.ts | 33 ++++++++++++++----- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/matchbox-frontend/src/app/igs/igs.component.html b/matchbox-frontend/src/app/igs/igs.component.html index 3606a69769b..3b1bc4e713e 100644 --- a/matchbox-frontend/src/app/igs/igs.component.html +++ b/matchbox-frontend/src/app/igs/igs.component.html @@ -58,5 +58,5 @@

Install an ImplementationGuide

Result of the last operation

- +
diff --git a/matchbox-frontend/src/app/igs/igs.component.ts b/matchbox-frontend/src/app/igs/igs.component.ts index 2ccee622076..60e437df54a 100644 --- a/matchbox-frontend/src/app/igs/igs.component.ts +++ b/matchbox-frontend/src/app/igs/igs.component.ts @@ -3,6 +3,7 @@ import { FhirConfigService } from '../fhirConfig.service'; import { UntypedFormControl, Validators } from '@angular/forms'; import FhirClient from 'fhir-kit-client'; import { FhirPathService } from '../fhirpath.service'; +import {OperationResult} from "../util/operation-result"; @Component({ selector: 'app-igs', @@ -20,7 +21,7 @@ export class IgsComponent { client: FhirClient; igs: fhir.r4.ImplementationGuide[]; errorMessage: string; - operationOutcome: fhir.r4.OperationOutcome; + operationResult: OperationResult | null = null; query = { _sort: 'title', @@ -51,7 +52,11 @@ export class IgsComponent { }) .catch((error) => { this.errorMessage = 'Error accessing FHIR server'; - this.operationOutcome = error.response.data; + if (error.response?.data) { + this.operationResult = OperationResult.fromOperationOutcome(error.response.data); + } else { + this.operationResult = OperationResult.fromMatchboxError(error.message); + } }); this.update = false; } @@ -112,12 +117,16 @@ export class IgsComponent { }) .then((response) => { this.errorMessage = 'Created Implementation Guide ' + this.addPackageId.value; - this.operationOutcome = response as fhir.r4.OperationOutcome; + this.operationResult = OperationResult.fromOperationOutcome(response as fhir.r4.OperationOutcome); this.search(); }) .catch((error) => { this.errorMessage = 'Error creating Implementation Guide ' + this.addPackageId.value; - this.operationOutcome = error.response.data; + if (error.response?.data) { + this.operationResult = OperationResult.fromOperationOutcome(error.response.data); + } else { + this.operationResult = OperationResult.fromMatchboxError(error.message); + } this.update = false; }); } @@ -144,12 +153,16 @@ export class IgsComponent { }) .then((response) => { this.errorMessage = 'Updated Implementation Guide ' + this.selection.packageId; - this.operationOutcome = response as fhir.r4.OperationOutcome; + this.operationResult = OperationResult.fromOperationOutcome(response as fhir.r4.OperationOutcome); this.search(); }) .catch((error) => { this.errorMessage = 'Error updating Implementation Guide ' + this.selection.packageId; - this.operationOutcome = error.response.data; + if (error.response?.data) { + this.operationResult = OperationResult.fromOperationOutcome(error.response.data); + } else { + this.operationResult = OperationResult.fromMatchboxError(error.message); + } this.update = false; }); } @@ -171,12 +184,16 @@ export class IgsComponent { }) .then((response) => { this.errorMessage = 'Deleted Implementation Guide Resource ' + this.selection.packageId; - this.operationOutcome = response as fhir.r4.OperationOutcome; + this.operationResult = OperationResult.fromOperationOutcome(response as fhir.r4.OperationOutcome); this.search(); }) .catch((error) => { this.errorMessage = 'Error deleting Implementation Guide ' + this.selection.packageId; - this.operationOutcome = error.response.data; + if (error.response?.data) { + this.operationResult = OperationResult.fromOperationOutcome(error.response.data); + } else { + this.operationResult = OperationResult.fromMatchboxError(error.message); + } this.update = false; }); }