UNPKG

return-style

Version:

Non-intrusively convert the result of any function or promise to the user's desired style.

13 lines (11 loc) 232 B
import { Awaitable } from '@blackglory/prelude' export async function getErrorAsync<E = Error>( fn: () => Awaitable<unknown> ): Promise<E | undefined> { try { await fn() } catch (err: any) { return err } return }