From 0dee2007e4b7e45008031387954dce38c849071a Mon Sep 17 00:00:00 2001 From: chimpdev Date: Fri, 3 Jan 2025 13:11:22 +0300 Subject: [PATCH] feat: add safeCall utility function for error handling in async operations --- src/lib/utils/safeCall.ts | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 src/lib/utils/safeCall.ts diff --git a/src/lib/utils/safeCall.ts b/src/lib/utils/safeCall.ts new file mode 100644 index 0000000..16d1227 --- /dev/null +++ b/src/lib/utils/safeCall.ts @@ -0,0 +1,9 @@ +async function safeCall(fn: () => Promise): Promise { + try { + return await fn(); + } catch { + return null; + } +} + +export default safeCall; \ No newline at end of file