UNPKG

@jplorg/jpl

Version:
34 lines (32 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.adaptError = adaptError; exports.adaptErrorsAsync = adaptErrorsAsync; exports.default = void 0; var _error = _interopRequireDefault(require("./error")); var _execution = _interopRequireDefault(require("./execution")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } /** Wrap occuring errors in a JPLExecutionError if they are not already a JPLError */ function adaptErrors(cb) { try { return cb(); } catch (err) { throw adaptError(err); } } var _default = exports.default = adaptErrors; /** Wrap occuring errors in a JPLExecutionError if they are not already a JPLError */ async function adaptErrorsAsync(cb) { try { return await cb(); } catch (err) { throw adaptError(err); } } /** Wrap error in a JPLExecutionError if it is not already a JPLError */ function adaptError(error) { if (!_error.default.is(error)) return new _execution.default(error.message); return error; }