fix: Unseen error on client action execution

This commit is contained in:
Tom Moor
2024-02-06 19:08:05 -05:00
parent 0ff0780869
commit 7bf403356a
2 changed files with 10 additions and 4 deletions

View File

@@ -119,7 +119,13 @@ export function actionToKBar(
} }
export async function performAction(action: Action, context: ActionContext) { export async function performAction(action: Action, context: ActionContext) {
return action.perform?.(context)?.catch((err: Error) => { const result = action.perform?.(context);
toast.error(err.message);
}); if (result instanceof Promise) {
return result.catch((err: Error) => {
toast.error(err.message);
});
}
return result;
} }

View File

@@ -111,7 +111,7 @@ export type Action = {
* Perform the action note this should generally not be called directly, use `performAction` * Perform the action note this should generally not be called directly, use `performAction`
* instead. Errors will be caught and displayed to the user as a toast message. * instead. Errors will be caught and displayed to the user as a toast message.
*/ */
perform?: (context: ActionContext) => Promise<any> | any; perform?: (context: ActionContext) => any;
children?: ((context: ActionContext) => Action[]) | Action[]; children?: ((context: ActionContext) => Action[]) | Action[];
}; };