[SDK] Make public-operations non throw (#18343)
Followup https://github.com/twentyhq/twenty/pull/18320
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import { type CommandResult } from '@/cli/public-operations/types';
|
||||
|
||||
export const runSafe = async <T>(
|
||||
operation: () => Promise<CommandResult<T>>,
|
||||
fallbackErrorCode: string,
|
||||
): Promise<CommandResult<T>> => {
|
||||
try {
|
||||
return await operation();
|
||||
} catch (error) {
|
||||
return {
|
||||
success: false,
|
||||
error: {
|
||||
code: fallbackErrorCode,
|
||||
message: error instanceof Error ? error.message : 'Unexpected error',
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user