"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const common_1 = require("@nestjs/common");
class HttpErrorResponse extends common_1.HttpException {
    constructor(message, status, data = null) {
        let responsePayload;
        if (Array.isArray(message)) {
            const errors = message;
            const properties = {};
            errors.forEach((error) => {
                if (!properties[error.path]) {
                    properties[error.path] = { errors: [] };
                }
                properties[error.path].errors.push(error.message);
            });
            responsePayload = {
                message: {
                    errors: errors.map((e) => `${e.message}`),
                    properties,
                },
                data: data || null,
                status: status || common_1.HttpStatus.BAD_REQUEST,
            };
        }
        else {
            responsePayload = {
                message: message || 'An error occurred',
                data: data || null,
                status: status || common_1.HttpStatus.INTERNAL_SERVER_ERROR,
            };
        }
        super(responsePayload, status || common_1.HttpStatus.INTERNAL_SERVER_ERROR);
    }
}
exports.default = HttpErrorResponse;
//# sourceMappingURL=httpErrorResponse.config.js.map