UNPKG

prostgles-types

Version:

Shared TypeScript object definitions for prostgles-client and prostgles-server

38 lines 1.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tryCatchV2 = void 0; const tryCatchV2 = (func) => { const startTime = Date.now(); try { const dataOrResult = func(); if (dataOrResult instanceof Promise) { return new Promise(async (resolve, reject) => { const result = await dataOrResult .then((data) => ({ data })) .catch((error) => { return { error, hasError: true, }; }); resolve({ ...result, duration: Date.now() - startTime, }); }); } return { data: dataOrResult, duration: Date.now() - startTime, }; } catch (error) { return { error, hasError: true, duration: Date.now() - startTime, }; } }; exports.tryCatchV2 = tryCatchV2; //# sourceMappingURL=tryCatchV2.js.map