Skip to content

Commit

Permalink
Wrap buildCurrent in try in case of unknown errors + verify no …
Browse files Browse the repository at this point in the history
…need to be async.
  • Loading branch information
NI committed Aug 27, 2019
1 parent 134f0f0 commit 9257bd4
Showing 1 changed file with 52 additions and 42 deletions.
94 changes: 52 additions & 42 deletions ui/widgets/connector.vue
Original file line number Diff line number Diff line change
Expand Up @@ -257,67 +257,77 @@ export default {
this.$emit("cancel", true);
},
cancel() {
if (this.cancelled) {
if (this.working) {
return;
}
this.cancelled = true;
if (this.working) {
if (this.cancelled) {
return;
}
this.cancelled = true;
this.sendCancel();
},
buildCurrent(next) {
this.current = buildEmptyCurrent();
try {
this.current = buildEmptyCurrent();
this.working = this.getConnector().wizard.started();
this.working = this.getConnector().wizard.started();
this.current.type = next.type();
this.current.data = next.data();
this.current.type = next.type();
this.current.data = next.data();
switch (this.current.type) {
case command.NEXT_PROMPT:
let fields = this.current.data.inputs();
switch (this.current.type) {
case command.NEXT_PROMPT:
let fields = this.current.data.inputs();
for (let i in fields) {
this.current.fields.push(buildField(i, fields[i]));
}
for (let i in fields) {
this.current.fields.push(buildField(i, fields[i]));
}
this.current.actionText = this.current.data.actionText();
this.current.submittable = true;
this.current.alert = true;
this.current.cancellable = true;
this.current.actionText = this.current.data.actionText();
this.current.submittable = true;
this.current.alert = true;
this.current.cancellable = true;
// Fallthrough
// Fallthrough
case command.NEXT_WAIT:
this.current.title = this.current.data.title();
this.current.message = this.current.data.message();
break;
case command.NEXT_WAIT:
this.current.title = this.current.data.title();
this.current.message = this.current.data.message();
break;
case command.NEXT_DONE:
this.working = false;
this.disabled = true;
if (!this.current.data.success()) {
this.current.title = this.current.data.error();
this.current.message = this.current.data.message();
} else {
this.$emit("done", this.current.data.data());
}
break;
default:
throw new Error("Unknown command type");
}
case command.NEXT_DONE:
this.working = false;
this.disabled = true;
if (!this.working) {
this.current.cancellable = false;
}
if (!this.current.data.success()) {
this.current.title = this.current.data.error();
this.current.message = this.current.data.message();
} else {
this.$emit("done", this.current.data.data());
}
break;
return next;
} catch (e) {
this.current.title = "Encountered an error";
this.current.message = e;
default:
throw new Error("Unknown command type");
}
this.working = false;
this.disabled = true;
if (!this.working) {
this.current.cancellable = false;
throw e;
}
return next;
},
getConnector() {
if (this.currentConnector === null) {
Expand Down Expand Up @@ -377,9 +387,9 @@ export default {
event.target.style.height = "";
event.target.style.height = event.target.scrollHeight + "px";
},
async verify(key, field, force) {
verify(key, field, force) {
try {
field.message = "" + (await field.field.verify(field.field.value));
field.message = "" + field.field.verify(field.field.value);
field.inputted = true;
field.verified = true;
field.error = "";
Expand Down

0 comments on commit 9257bd4

Please sign in to comment.