UNPKG

@imigueldiaz/mongodb-labeler

Version:

A MongoDB-based labeling system for content moderation with cryptographic signing

28 lines (27 loc) 652 B
/** * Type guard to check if an error is an instance of Error */ export function isError(error) { return error instanceof Error; } /** * Safe error handler for async operations */ export async function safeAsyncOperation(operation, errorPrefix = 'Operation failed') { try { return await operation(); } catch (error) { console.error(errorPrefix + ':', isError(error) ? error.message : String(error)); throw error; } } /** * Get a safe error message from any error type */ export function getErrorMessage(error) { if (isError(error)) { return error.message; } return String(error); }