"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ErrorMessages = exports.ErrorReasons = void 0;
exports.getErrorType = getErrorType;
exports.createErrorResponse = createErrorResponse;
exports.ErrorReasons = {
    BadArguments: 'BadArgumentsError',
    Unauthorized: 'NotAuthorized',
    NotFound: 'NotFoundError',
    RateLimit: 'RateLimitError',
    InternalError: 'InternalError',
    ConnectionError: 'ConnectionError',
    Unknown: 'UnknownError',
};
exports.ErrorMessages = {
    [exports.ErrorReasons.Unauthorized]: 'Invalid GitHub token. Please sign out from your GitHub account using VSCode UI and try again',
    [exports.ErrorReasons.InternalError]: 'Internal error: matches to public code will not be detected. It is advised to disable Copilot completions until the service is reconnected.',
    [exports.ErrorReasons.RateLimit]: `You've reached your quota and limit, code matching will be unavailable until the limit resets`,
};
function getErrorType(code) {
    if (code === 401) {
        return exports.ErrorReasons.Unauthorized;
    }
    else if (code === 400) {
        return exports.ErrorReasons.BadArguments;
    }
    else if (code === 404) {
        return exports.ErrorReasons.NotFound;
    }
    else if (code === 429) {
        return exports.ErrorReasons.RateLimit;
    }
    else if (code >= 500 && code < 600) {
        return exports.ErrorReasons.InternalError;
    }
    else if (code >= 600) {
        // internal error codes for reconnecting / fully disconnected state. open to changing.
        // Separated because a 500 indicates a server error, but a 600 indicates the client is attempting
        // to recover.
        return exports.ErrorReasons.ConnectionError;
    }
    return exports.ErrorReasons.Unknown;
}
/**
 * Helper method to combine a fetch response and a snippy error response into an
 * object which conforms to our other error response interfaces. As seen in, e.g., extension/src/auth.ts.
 * @param code HTTP status code
 * @param msg
 * @param meta Any additional data, typically an object
 * @returns FormattedSnippyError
 */
function createErrorResponse(code, msg, meta = {}) {
    const reason = getErrorType(Number(code));
    const errorResponse = {
        kind: 'failure',
        reason,
        code: Number(code),
        msg,
        meta,
    };
    return errorResponse;
}
//# sourceMappingURL=errorCreator.js.map