Skip to content

Commit

Permalink
Improve error handling when testing mappings in the UI
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Mar 29, 2024
1 parent c2a3911 commit 7788302
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 26 deletions.
15 changes: 7 additions & 8 deletions dynamic-mapping-ui/src/mapping/core/c8y-agent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export class C8YAgent {
}

async createMEAO(context: ProcessingContext) {
let result: any;
let result: Promise<any>;
let error: string = '';
const currentRequest =
context.requests[context.requests.length - 1].request;
Expand Down Expand Up @@ -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 '';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[disabled]="disabled$ | async"
[headerClasses]="'modal-header dialog-header'"
>
<div>
<div class="p-24">
<c8y-form-group *ngIf="duplicate">
<div>
<span>{{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,24 @@ <h4>Add Mapping</h4>
[disabled]="true"
#addMappingRef
>
<p class="p-16 text-center text-medium separator-bottom sticky-top bg-white">
{{ "Select mapping type for target" | translate }}
</p>
<div class="modal-inner-scroll animated fadeIn">
<div class="list-group list-group-links" [formGroup]="formGroupStep">
<ng-container *ngFor="let q of MappingType | keyvalue">
<button
*ngIf="direction !== Direction.OUTBOUND || q.value === 'JSON'"
class="list-group-item"
title="{{ q.value }}"
(click)="onSelectMappingType(q.value)"
>
<i [c8yIcon]="'rules m-r-4'"></i>
<span>{{ q.value }}</span>
</button>
</ng-container>
</div>
<div>
<p class="p-b-24 text-center text-medium separator-bottom sticky-top bg-white">
{{ "Select mapping type for target" | translate }}
</p>
<div class="p-24 modal-inner-scroll animated fadeIn">
<div class="list-group list-group-links" [formGroup]="formGroupStep">
<ng-container *ngFor="let q of MappingType | keyvalue">
<button
*ngIf="direction !== Direction.OUTBOUND || q.value === 'JSON'"
class="list-group-item"
title="{{ q.value }}"
(click)="onSelectMappingType(q.value)"
>
<i [c8yIcon]="'rules m-r-4'"></i>
<span>{{ q.value }}</span>
</button>
</ng-container>
</div>
</div>
</div>
</c8y-modal>
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,7 @@
<c8y-stepper-buttons
class="col-xs-12 d-block card-footer p-24 separator"
(onCustom)="onCommitButton()"
(onCancel)="cancel.emit()"
(onBack)="onBackStep($event)"
[labels]="{ custom: 'Confirm' }"
>
Expand Down

0 comments on commit 7788302

Please sign in to comment.