UNPKG

@johang/trycatch

Version:
21 lines (20 loc) 527 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tryCatch = void 0; /** * A try-catch wrapper function that returns an object, * similarly structured as a Golang async action. * @param asyncAction * @returns {Response} */ const tryCatch = async (asyncAction) => { try { const data = await asyncAction; return { data, error: null }; } catch (error) { const err = error; return { data: null, error: err }; } }; exports.tryCatch = tryCatch;