Documentation / @zerotal/core / helpers / rescue
Function: rescue()
rescue<
T>(callback,fallback):Promise<T>
Defined in: helpers/index.ts:201
Execute a callback and return its value. On exception, return fallback
instead of propagating. Fallback may itself be a function that receives
the caught error.
Type Parameters
T
T
Parameters
callback
() => T | Promise<T>
fallback
T | ((error) => T | Promise<T>)
Returns
Promise<T>
Example
const price = await rescue(() => stripe.getPrice(id), 0);
const user = await rescue(() => User.findOrFail(id), (e) => { log(e); return null; });