{"size": 2331, "ext": "js", "max_stars_repo_path": "backend/nest-theme/dist/cjs/error-handler.js", "max_stars_repo_name": "ribajs/riba", "max_stars_repo_stars_event_min_datetime": "2018-11-24T16:48:32.000Z", "max_stars_repo_stars_event_max_datetime": "2021-12-06T22:09:00.000Z", "max_issues_repo_path": "backend/nest-theme/dist/cjs/error-handler.js", "max_issues_repo_name": "ribajs/riba", "max_issues_repo_issues_event_min_datetime": "2019-11-17T03:39:38.000Z", "max_issues_repo_issues_event_max_datetime": "2020-10-25T09:54:35.000Z", "max_forks_repo_path": "backend/nest-theme/dist/cjs/error-handler.js", "max_forks_repo_name": "ribajs/riba", "max_forks_repo_forks_event_min_datetime": "2020-04-16T12:04:41.000Z", "max_forks_repo_forks_event_max_datetime": "2020-10-11T14:15:16.000Z"}
{"max_stars_count": 12, "max_issues_count": 5, "max_forks_count": 4, "avg_line_length": 30.6710526316, "max_line_length": 89, "alphanum_fraction": 0.6027456027}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleError = exports.getStack = exports.getMessage = exports.getStatus = void 0;
const common_1 = require("@nestjs/common");
const getStatus = (exception) => {
    if (exception instanceof common_1.HttpException) {
        return exception.getStatus();
    }
    if (typeof exception !== 'string' && exception.status) {
        return exception.status;
    }
    return common_1.HttpStatus.INTERNAL_SERVER_ERROR;
};
exports.getStatus = getStatus;
const getMessage = (exception) => {
    let message = 'Internal server error';
    if (typeof exception === 'string') {
        message = exception;
    }
    else if (exception instanceof common_1.HttpException) {
        const excResp = exception.getResponse();
        message =
            typeof excResp === 'string'
                ? excResp
                : excResp.message || JSON.stringify(excResp);
    }
    else if (exception instanceof Error) {
        message = exception.message || message;
    }
    return `${message}`;
};
exports.getMessage = getMessage;
const getStack = (exception) => {
    let stack;
    if (typeof exception === 'string') {
        stack = new Error(exception).stack;
        return stack.split('\n');
    }
    if (!stack && exception instanceof common_1.HttpException) {
        const excResp = exception.getResponse();
        stack = excResp.stack || exception.stack;
        if (Array.isArray(stack)) {
            return stack;
        }
        return stack.split('\n');
    }
    if (!exception.stack) {
        stack = new Error().stack;
    }
    if (!stack) {
        stack = exception.stack;
    }
    if (Array.isArray(stack)) {
        return stack;
    }
    return stack.split('\n');
};
exports.getStack = getStack;
const handleError = (error) => {
    if (error instanceof common_1.HttpException) {
        return error;
    }
    try {
        return new common_1.HttpException({
            message: (0, exports.getMessage)(error),
            stack: (0, exports.getStack)(error),
        }, (0, exports.getStatus)(error));
    }
    catch (error) {
        return new common_1.HttpException({
            message: "Can't handle error",
        }, 500);
    }
};
exports.handleError = handleError;
//# sourceMappingURL=error-handler.js.map