Skip to content

Commit

Permalink
🎨 [Frontend] Handle LongRunningTask errors better (#6485)
Browse files Browse the repository at this point in the history
  • Loading branch information
odeimaiz authored Oct 2, 2024
1 parent 8118841 commit cd50cbe
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ qx.Class.define("osparc.FlashMessenger", {
* @param {osparc.ui.message.FlashMessage} flashMessage FlashMessage element to show.
*/
__showMessage: function(flashMessage) {
if (!flashMessage.getMessage()) {
flashMessage.setMessage(qx.locale.Manager.tr("No message"));
}

this.__messages.remove(flashMessage);
this.__messageContainer.resetDecorator();
this.__messageContainer.add(flashMessage);
Expand All @@ -113,7 +117,8 @@ qx.Class.define("osparc.FlashMessenger", {

let duration = flashMessage.getDuration();
if (duration === null) {
const wordCount = flashMessage.getMessage() ? flashMessage.getMessage().split(" ").length : 20;
const message = flashMessage.getMessage();
const wordCount = message.split(" ").length;
duration = Math.max(5500, wordCount*500); // An average reader takes 300ms to read a word
}
if (duration !== 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1781,8 +1781,8 @@ qx.Class.define("osparc.dashboard.StudyBrowser", {
this._updateStudyData(duplicatedStudyData);
});
task.addListener("pollingError", e => {
const errMsg = e.getData();
const msg = this.tr("Something went wrong Duplicating the study<br>") + errMsg;
const err = e.getData();
const msg = this.tr("Something went wrong Duplicating the study<br>") + err.message;
finished(msg, "ERROR");
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,8 @@ qx.Class.define("osparc.dashboard.TemplateBrowser", {
this.reloadResources();
});
task.addListener("pollingError", e => {
const errMsg = e.getData();
const msg = this.tr("Something went wrong Publishing the study<br>") + errMsg;
const err = e.getData();
const msg = this.tr("Something went wrong Publishing the study<br>") + err.message;
finished(msg, "ERROR");
});
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ qx.Class.define("osparc.data.PollTask", {
return resp.json();
}
const errMsg = qx.locale.Manager.tr("Failed polling status");
this.fireDataEvent("pollingError", errMsg);
throw new Error(errMsg);
const err = new Error(errMsg);
this.fireDataEvent("pollingError", err);
throw err;
})
.then(data => {
if (data === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ qx.Class.define("osparc.data.PollTasks", {
throw Error("Status missing");
}
})
.catch(errMsg => reject(errMsg));
.catch(err => reject(err));
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ qx.Class.define("osparc.study.Utils", {
resolve(resultData);
});
task.addListener("pollingError", e => {
reject("Polling Error");
const err = e.getData();
reject(err);
});
})
.catch(err => reject(err));
Expand Down Expand Up @@ -250,8 +251,8 @@ qx.Class.define("osparc.study.Utils", {
resolve(studyData["uuid"]);
}, this);
task.addListener("pollingError", e => {
const errMsg = e.getData();
reject(errMsg);
const err = e.getData();
reject(err);
}, this);
})
.catch(err => reject(err));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,23 +119,23 @@ qx.Class.define("osparc.ui.message.FlashMessage", {
control = new qx.ui.basic.Image().set({
alignY: "middle"
});
this.getChildControl("message-layout").add(control);
this.getChildControl("message-layout").addAt(control, 0);
break;
case "message":
control = new qx.ui.basic.Label().set({
font: "text-16",
selectable: true,
rich: true
});
this.getChildControl("message-layout").add(control, {
this.getChildControl("message-layout").addAt(control, 1, {
flex: 1
});
break;
case "closebutton":
control = new osparc.ui.basic.IconButton("@MaterialIcons/close/16", () => this.fireEvent("closeMessage")).set({
alignY: "middle"
});
this.getChildControl("message-layout").add(control);
this.getChildControl("message-layout").addAt(control, 2);
break;
}
return control || this.base(arguments, id);
Expand Down

0 comments on commit cd50cbe

Please sign in to comment.