Skip to content

Commit

Permalink
fix(snackbar): catch action button handler error
Browse files Browse the repository at this point in the history
  • Loading branch information
njfamirm committed Jan 5, 2025
1 parent 17a208a commit c05e354
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions packages/snackbar/src/lib/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const logger = createLogger(`${__package_name__}`);
/**
* Store the function to close the last snackbar.
*/
let closeLastSnackbar: (() => Promise<void>) | null = null;
let closeLastSnackbar: (() => MaybePromise<void>) | null = null;

/**
* Store the function to unsubscribe the action button handler after close or action button clicked.
Expand Down Expand Up @@ -53,7 +53,16 @@ function createSnackbarElement(options: SnackbarOptions): SnackbarElement {
function handleActionButtonClick(closeSnackbar: () => Promise<void>, handler?: SnackbarActionHandler): Promise<void> {
logger.logMethod?.('handleActionButtonClick');

handler?.();
// non-blocking to handler done
(async () => {
try {
await handler!();
}
catch (error) {
logger.error('handleActionButtonClick', 'call_handler_failed', error);
}
})();

return closeSnackbar();
}

Expand Down

0 comments on commit c05e354

Please sign in to comment.