From 2893ad956df0c1e22d5a818b0898b4c72ccd1cec Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Tue, 3 Aug 2021 10:09:19 -0400 Subject: [PATCH] Notify user of error if confirmation dialog rejects promise (#3179) Signed-off-by: Sebastian Malton --- .../confirm-dialog/confirm-dialog.tsx | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/renderer/components/confirm-dialog/confirm-dialog.tsx b/src/renderer/components/confirm-dialog/confirm-dialog.tsx index 47e7eab665..a4a8bdcddf 100644 --- a/src/renderer/components/confirm-dialog/confirm-dialog.tsx +++ b/src/renderer/components/confirm-dialog/confirm-dialog.tsx @@ -28,6 +28,7 @@ import { cssNames, noop, prevDefault } from "../../utils"; import { Button, ButtonProps } from "../button"; import { Dialog, DialogProps } from "../dialog"; import { Icon } from "../icon"; +import { Notifications } from "../notifications"; export interface ConfirmDialogProps extends Partial { } @@ -90,7 +91,14 @@ export class ConfirmDialog extends React.Component { ok = async () => { try { this.isSaving = true; - await Promise.resolve(this.params.ok()).catch(noop); + await (async () => this.params.ok())(); + } catch (error) { + Notifications.error( + <> +

Confirmation action failed:

+

{error?.message ?? error?.toString?.() ?? "Unknown error"}

+ + ); } finally { this.isSaving = false; dialogState.isOpen = false; @@ -103,7 +111,14 @@ export class ConfirmDialog extends React.Component { close = async () => { try { - await Promise.resolve(this.params.cancel()).catch(noop); + await Promise.resolve(this.params.cancel()); + } catch (error) { + Notifications.error( + <> +

Cancelling action failed:

+

{error?.message ?? error?.toString?.() ?? "Unknown error"}

+ + ); } finally { this.isSaving = false; dialogState.isOpen = false;