@snap/camera-kit
Version:
Camera Kit Web
35 lines • 1.48 kB
JavaScript
import { ensureError } from "../common/errorHelpers";
const lensCoreErrorValue = {
LensDeserialization: 0,
Validation: 1,
Uncategorized: 2,
LensExecution: 3,
Abort: 4,
Uninitialized: 5,
};
const lensCoreErrorName = Object.fromEntries(Object.entries(lensCoreErrorValue).map((entry) => [entry[1], entry[0]]));
export function wrapLensCoreError(unknownError, isFrameError) {
var _a, _b, _c, _d, _e;
const lcError = ensureError(unknownError);
const error = new Error(lcError.message.split("\n")[0], {
cause: lcError.otherExceptions || ((_a = lcError.cause) === null || _a === void 0 ? void 0 : _a.metadata)
? {
otherExceptions: lcError.otherExceptions,
metadata: (_b = lcError.cause) === null || _b === void 0 ? void 0 : _b.metadata,
}
: undefined,
});
const lcErrorType = (_d = (_c = lcError.cause) === null || _c === void 0 ? void 0 : _c.type) === null || _d === void 0 ? void 0 : _d.value;
const name = `LensCore${(_e = lensCoreErrorName[lcErrorType]) !== null && _e !== void 0 ? _e : "Unknown"}Error`;
error.name = name;
error.isFrameError = isFrameError;
if (lcError.stack) {
const [_, ...stackLines] = lcError.stack.split("\n");
if (error.stack) {
stackLines.unshift(error.stack.split("\n")[0]);
}
error.stack = stackLines.join("\n");
}
return error;
}
//# sourceMappingURL=lensCoreError.js.map