UNPKG

dont-throw

Version:
32 lines (31 loc) 730 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tryCatch = void 0; function tryCatch(fn) { try { const res = fn(); const isAsync = Promise.resolve(res) === res; if (isAsync) return Promise.resolve(res) .then((ret) => ({ success: true, data: ret, })) .catch((error) => ({ success: false, error, })); return { success: true, data: res, }; } catch (e) { // is sync return { success: false, error: e, }; } } exports.tryCatch = tryCatch;