import { safeResult } from "https://deno.land/x/domain_functions@v2.6.0/src/index.ts";
A functions that turns the result of its callback into a Result object.
Examples
const result = await safeResult(() => ({
message: 'hello',
}))
// the type of result is Result<{ message: string }>
if (result.success) {
console.log(result.data.message)
}
const result = await safeResult(() => ({ message: 'hello', })) // the type of result is Result<{ message: string }> if (result.success) { console.log(result.data.message) }
const result = await safeResult(() => { throw new Error('something went wrong') }) // the type of result is Result if (!result.success) { console.log(result.errors[0].message) }
Parameters
fn: () => T