"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseUnknowError = exports.parseAxiosError = exports.parseZodError = exports.isAxiosError = exports.isZodError = void 0;
const axios_1 = require("axios");
const zod_1 = require("zod");
const zod_validation_error_1 = require("zod-validation-error");
const isZodError = (error) => {
    return error instanceof zod_1.ZodError;
};
exports.isZodError = isZodError;
const isAxiosError = (error) => {
    return error instanceof axios_1.AxiosError;
};
exports.isAxiosError = isAxiosError;
const parseZodError = (error) => {
    const parsedError = (0, zod_validation_error_1.fromZodError)(error);
    return {
        date: new Date().toISOString(),
        text: { en: parsedError.message },
        error: {
            category: 'SERVER_ERROR',
            message: parsedError.message,
        },
    };
};
exports.parseZodError = parseZodError;
const parseAxiosError = (error) => {
    var _a, _b;
    return {
        date: new Date().toISOString(),
        text: {
            en: `${(_a = error.status) !== null && _a !== void 0 ? _a : '(no status code)'} Error: ${error.message}`,
        },
        error: {
            category: 'BAD_REQUEST',
            message: `${(_b = error.status) !== null && _b !== void 0 ? _b : '(no status code)'} Error: ${error.message}`,
        },
    };
};
exports.parseAxiosError = parseAxiosError;
const parseUnknowError = (error) => {
    const message = error.message;
    return {
        date: new Date().toISOString(),
        text: { en: message },
        error: {
            category: 'SERVER_ERROR',
            message,
        },
    };
};
exports.parseUnknowError = parseUnknowError;
//# sourceMappingURL=error.js.map