"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.sendApiError = void 0;
const axios_1 = __importDefault(require("axios"));
const index_1 = require("./index");
const sendApiError = (res, error) => {
    let status;
    let message;
    if (axios_1.default.isAxiosError(error)) {
        status = error.response?.status;
        message = error.response?.statusText;
    }
    else if (error instanceof index_1.ErrorWithCode) {
        status = error.code;
        message = error.message;
    }
    else if (error instanceof Error) {
        message = error.message;
    }
    if (status === 401) {
        status = 500;
        message = 'Authorization failed';
    }
    (0, index_1.sendError)(res, message, status || 500);
};
exports.sendApiError = sendApiError;
