"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleErrorMessage = void 0;
const zod_validation_error_1 = require("zod-validation-error");
const zod_1 = require("zod");
const axios_1 = require("axios");
const handleErrorMessage = async (err, onError) => {
    var _a, _b;
    if (err instanceof zod_1.ZodError) {
        const error = (0, zod_validation_error_1.fromZodError)(err);
        await onError({
            events: [
                {
                    date: new Date().toISOString(),
                    text: { en: error.message },
                    error: {
                        category: 'WRONG_INPUT',
                        message: error.message,
                    },
                },
            ],
        });
    }
    else if (err instanceof axios_1.AxiosError) {
        await onError({
            events: [
                {
                    date: new Date().toISOString(),
                    text: {
                        en: `${(_a = err.status) !== null && _a !== void 0 ? _a : '(no status code)'} Error: ${err.message}`,
                    },
                    error: {
                        category: 'SERVER_ERROR',
                        message: `${(_b = err.status) !== null && _b !== void 0 ? _b : '(no status code)'} Error: ${err.message}`,
                    },
                },
            ],
        });
    }
    else {
        const message = err.message;
        await onError({
            events: [
                {
                    date: new Date().toISOString(),
                    text: { en: message },
                    error: {
                        category: 'SERVER_ERROR',
                        message,
                    },
                },
            ],
        });
    }
};
exports.handleErrorMessage = handleErrorMessage;
//# sourceMappingURL=errorHandler.js.map