From 77883029e17470ca6a6899d965ba2e6cafc50e2c Mon Sep 17 00:00:00 2001 From: sagIoTPower Date: Fri, 29 Mar 2024 09:45:19 +0100 Subject: [PATCH] Improve error handling when testing mappings in the UI --- .../src/mapping/core/c8y-agent.service.ts | 15 ++++---- .../edit-substitution-modal.component.html | 2 +- .../mapping-type/mapping-type.component.html | 36 ++++++++++--------- .../step-main/mapping-stepper.component.html | 1 + 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/dynamic-mapping-ui/src/mapping/core/c8y-agent.service.ts b/dynamic-mapping-ui/src/mapping/core/c8y-agent.service.ts index 831d0ac3..2759c19f 100644 --- a/dynamic-mapping-ui/src/mapping/core/c8y-agent.service.ts +++ b/dynamic-mapping-ui/src/mapping/core/c8y-agent.service.ts @@ -56,7 +56,7 @@ export class C8YAgent { } async createMEAO(context: ProcessingContext) { - let result: any; + let result: Promise; let error: string = ''; const currentRequest = context.requests[context.requests.length - 1].request; @@ -97,31 +97,30 @@ export class C8YAgent { result = this.inventory.create(p, context); } } else { - error = `Payload is not a valid:${context.mapping.targetAPI}`; + error = `Payload is not a valid: ${context.mapping.targetAPI}`; } } if (error != '') { - this.alert.danger(`Failed to tested mapping: ${error}`); + this.alert.danger(`Failed to test mapping: ${error}`); return ''; } try { const { data, res } = await result; - // console.log ("My data:", data ); if (res.status == 200 || res.status == 201) { // this.alert.success("Successfully tested mapping!"); return data; } else { const e = await res.text(); - this.alert.danger(`Failed to tested mapping: ${e}`); + this.alert.danger(`Failed to test mapping: ${e}`); context.requests[context.requests.length - 1].error = e; return ''; } } catch (e) { - const { data } = await e; - this.alert.danger(`Failed to tested mapping: ${data}`); - context.requests[context.requests.length - 1].error = e; + const { res } = await e; + this.alert.danger(`Failed to test mapping: ${res.statusText}`); + context.requests[context.requests.length - 1].error = res.statusText; return ''; } } diff --git a/dynamic-mapping-ui/src/mapping/edit/edit-substitution-modal.component.html b/dynamic-mapping-ui/src/mapping/edit/edit-substitution-modal.component.html index e8b51f75..ef1788b6 100644 --- a/dynamic-mapping-ui/src/mapping/edit/edit-substitution-modal.component.html +++ b/dynamic-mapping-ui/src/mapping/edit/edit-substitution-modal.component.html @@ -6,7 +6,7 @@ [disabled]="disabled$ | async" [headerClasses]="'modal-header dialog-header'" > -
+
{{ diff --git a/dynamic-mapping-ui/src/mapping/mapping-type/mapping-type.component.html b/dynamic-mapping-ui/src/mapping/mapping-type/mapping-type.component.html index 5cc8b82b..f9e4011a 100644 --- a/dynamic-mapping-ui/src/mapping/mapping-type/mapping-type.component.html +++ b/dynamic-mapping-ui/src/mapping/mapping-type/mapping-type.component.html @@ -31,22 +31,24 @@

Add Mapping

[disabled]="true" #addMappingRef > -

- {{ "Select mapping type for target" | translate }} -

-