All files type-exception.js

0% Statements 0/44
0% Branches 0/35
0% Functions 0/9
0% Lines 0/42

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                                                                                                                                                 
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class TypeException extends Error {
    constructor(message, innerError, aggregateErrors) {
        super(message);
        this._data = {};
        this._innerError = innerError;
        this._aggregateErrors = aggregateErrors;
    }
    innerError() {
        return this._innerError || null;
    }
    aggregateErrors() {
        return this._aggregateErrors || null;
    }
    data() {
        return this._data;
    }
    tryAddData(key, value) {
        try {
            if (!key)
                return false;
            if (key.replace(/\s/g, "").length < 1)
                return false;
            if (this._data[key])
                return false;
            this._data[key] = value;
            return true;
        }
        catch (err) {
            console.log("Ocurrió un error al agregar el item al diccionario de datos de errores " + err.toString());
            return false;
        }
    }
    toStringWithData(value, tabIndex = 0) {
        let output = '';
        let tabs = "\t".repeat(tabIndex);
        //Se anexa el mensaje
        if (tabIndex > 0)
            output = output + tabs + "InnerException: " + value.message;
        else
            output = output + tabs + value.message;
        //Se anexa el stacktrace
        if (value.stack && value.stack.replace(/\s/g, "").length > 0)
            output = output + value.stack.split('\n').map(x => tabs + x).join('');
        if (value instanceof TypeException) {
            //Se anexa el data
            if (value.data && value.data.length > 0) {
                let data = "'Data': " + JSON.stringify(value.data);
                data = data.split("\n").map(x => tabs + x).join("");
                output = output + data;
            }
            //Se muestran los errores hijos
            if (value.aggregateErrors && value.aggregateErrors.length > 0) {
                value.aggregateErrors.forEach(err => {
                    if (err instanceof TypeException)
                        output = output + err.toStringWithData(err, tabIndex + 1);
                    else
                        output = output.toString();
                });
            }
            if (value.innerError != null) {
                if (value._innerError && value._innerError instanceof TypeException) {
                    var typedInnerError = value.innerError;
                    output = output + typedInnerError.toStringWithData(typedInnerError, tabIndex + 1);
                }
            }
        }
        return output;
    }
}
exports.TypeException = TypeException;
//# sourceMappingURL=type-exception.js.map