Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add error handling to save function #211

Merged
merged 1 commit into from
Jun 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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