"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseError = exports.getApiErrorStatus = exports.isApiError = exports.isNetworkError = exports.isFetchBaseQueryError = void 0;
/**
 * Type guard to check if error is a FetchBaseQueryError
 */
function isFetchBaseQueryError(error) {
    return typeof error === "object" && error !== null && "status" in error;
}
exports.isFetchBaseQueryError = isFetchBaseQueryError;
/**
 * Check if the error is a network connectivity error (no internet, timeout, etc.)
 */
function isNetworkError(error) {
    if (!isFetchBaseQueryError(error)) {
        return false;
    }
    return error.status === "FETCH_ERROR" || error.status === "TIMEOUT_ERROR";
}
exports.isNetworkError = isNetworkError;
/**
 * Check if the error is an API error with HTTP status code (4xx, 5xx)
 */
function isApiError(error) {
    if (!isFetchBaseQueryError(error)) {
        return false;
    }
    return typeof error.status === "number";
}
exports.isApiError = isApiError;
/**
 * Get HTTP status code from API error, or undefined if not an API error
 */
function getApiErrorStatus(error) {
    if (!isFetchBaseQueryError(error) || typeof error.status !== "number") {
        return undefined;
    }
    return error.status;
}
exports.getApiErrorStatus = getApiErrorStatus;
/**
 * Parse error into a structured ErrorInfo object
 */
function parseError(error) {
    return {
        hasError: !!error,
        isNetworkError: isNetworkError(error),
        isApiError: isApiError(error),
        apiStatus: getApiErrorStatus(error),
    };
}
exports.parseError = parseError;
//# sourceMappingURL=errorUtils.js.map