Skip to content

Commit

Permalink
Add error handling to save function (hashicorp-forge#211)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffdaley committed Jun 14, 2023
1 parent 4149a39 commit fcc1ac3
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions web/app/components/document/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,16 +216,20 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC

@action maybeShowFlashError(error: Error, title: string) {
if (!this.modalIsActive) {
this.flashMessages.add({
title,
message: error.message,
type: "critical",
timeout: 6000,
extendedTimeout: 1000,
});
this.showFlashError(error, title);
}
}

showFlashError(error: Error, title: string) {
this.flashMessages.add({
title,
message: error.message,
type: "critical",
timeout: 6000,
extendedTimeout: 1000,
});
}

@action showFlashSuccess(title: string, message: string) {
this.flashMessages.add({
message,
Expand All @@ -236,13 +240,11 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC
});
}

updateProduct = restartableTask(
async (product: string) => {
this.product = product;
await this.save.perform("product", this.product);
// productAbbreviation is computed by the back end
}
);
updateProduct = restartableTask(async (product: string) => {
this.product = product;
await this.save.perform("product", this.product);
// productAbbreviation is computed by the back end
});

save = task(async (field: string, val: string | HermesUser[]) => {
if (field && val) {
Expand All @@ -261,7 +263,8 @@ export default class DocumentSidebarComponent extends Component<DocumentSidebarC
} catch (err) {
// revert field value on failure
(this as any)[field] = val;
console.error(err);

this.showFlashError(err as Error, "Unable to save document");
}
}
});
Expand Down

0 comments on commit fcc1ac3

Please sign in to comment.