UNPKG

msw

Version:

Seamless REST/GraphQL API mocking library for browser and Node.js.

12 lines (11 loc) 254 B
export function tryCatch<Fn extends (...args: any[]) => any>( fn: Fn, onException?: (error: Error) => void, ): ReturnType<Fn> | undefined { try { const result = fn() return result } catch (error) { onException?.(error as Error) } }