UNPKG

@metamask/kernel-errors

Version:
35 lines 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.marshalError = marshalError; const utils_1 = require("@metamask/utils"); const constants_ts_1 = require("../constants.cjs"); const isOcapError_ts_1 = require("../utils/isOcapError.cjs"); /** * Marshals an error into a {@link MarshaledError}. * * @param error - The error to marshal. * @returns The marshaled error. */ function marshalError(error) { const output = { [constants_ts_1.ErrorSentinel]: true, message: error.message, }; if (error.cause) { output.cause = error.cause instanceof Error ? marshalError(error.cause) : JSON.stringify(error.cause); } if (error.stack) { output.stack = error.stack; } if ((0, isOcapError_ts_1.isOcapError)(error)) { output.code = error.code; if (error.data) { output.data = (0, utils_1.getSafeJson)(error.data); } } return harden(output); } //# sourceMappingURL=marshalError.cjs.map