pig-dam-core
Version:
Library that should be included in every Pig DAM project we build
31 lines (30 loc) • 1.04 kB
JavaScript
;
/**
* Date: 5/24/20
* Time: 9:29 PM
* @license MIT (see project's LICENSE file)
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getReverseErrorThrowSequence = exports.getErrorThrowSequence = void 0;
const pig_1 = require("./pig");
/**
* How do you translate a single error into a "throw sequence". Generally we cannot.
* BUT if they are PigErrors and they were created with "child" errors then we can
* recreate the scene of the crime.
* Builds the sequence in the order of time - from the inside out.
*/
function getErrorThrowSequence(error) {
if (error instanceof pig_1.PigError && error.error !== undefined) {
return getErrorThrowSequence(error.error)
.concat(error);
}
return [error];
}
exports.getErrorThrowSequence = getErrorThrowSequence;
/**
* reverses `getErrorThrowSequence`
*/
function getReverseErrorThrowSequence(error) {
return getErrorThrowSequence(error).reverse();
}
exports.getReverseErrorThrowSequence = getReverseErrorThrowSequence;