Skip to content

Commit

Permalink
Move try catch block to correct place, make sure onRequestDone is cal…
Browse files Browse the repository at this point in the history
…led in case of callDittoREST method error thrown

Signed-off-by: Vasil Vasilev <vasil.vasilev@bosch.com>
  • Loading branch information
vvasilevbosch committed Nov 7, 2023
1 parent ec3a108 commit 4237843
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions ui/modules/piggyback/piggyback.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,40 +204,42 @@ async function submitPiggybackCommand() {
if (isCommandValid()) {
dom.responseStatus.innerHTML = REQUEST_IN_PROGRESS_MESSAGE;
Utils.setEditorValue(aceResponse, '');
try {
let path = buildPath(
dom.serviceSelector.value,
dom.instanceSelector.value,
dom.timeout.value
);

let piggybackCommandBody = Templates.buildPiggybackCommand(
dom.targetActorSelection.value,
JSON.parse(aceHeadersEditor.getValue()),
JSON.parse(aceCommandEditor.getValue())
);

let promise = new Promise((resolve, reject) => {
onRequestInProgress(reject);
let path = buildPath(
dom.serviceSelector.value,
dom.instanceSelector.value,
dom.timeout.value
);

let piggybackCommandBody = Templates.buildPiggybackCommand(
dom.targetActorSelection.value,
JSON.parse(aceHeadersEditor.getValue()),
JSON.parse(aceCommandEditor.getValue())
);

let promise = new Promise((resolve, reject) => {
onRequestInProgress(reject);
try {
API.callDittoREST('POST', path, piggybackCommandBody, null, true, true)
.then(result => resolve(result))
.catch(err => reject(err));
});
promise.then((result: any) => {
onRequestDone();
result.json().then(resultJson => {
Utils.setEditorValue(aceResponse, stringifyPretty(resultJson));
dom.responseStatus.innerHTML = result.status;
});
}).catch(err => {
} catch (err) {
onRequestDone();
Utils.setEditorValue(aceResponse, err.message);
dom.responseStatus.innerHTML = REQUEST_ERROR_MESSAGE;
}
});
promise.then((result: any) => {
onRequestDone();
result.json().then(resultJson => {
Utils.setEditorValue(aceResponse, stringifyPretty(resultJson));
dom.responseStatus.innerHTML = result.status;
});
} catch (err) {
Utils.showError(`Error when executing piggyback command${err}`);
}).catch(err => {
onRequestDone();
Utils.setEditorValue(aceResponse, err.message);
dom.responseStatus.innerHTML = REQUEST_ERROR_MESSAGE;
}
});

}

function isCommandValid() {
Expand Down

0 comments on commit 4237843

Please sign in to comment.