• Gets the current user's manga list from AniList.

    Parameters

    • token: string

      The user's access token.

    • OptionalabortSignal: AbortSignal

      Optional AbortSignal to cancel the request.

    Returns Promise<UserMediaList>

    The user's manga list organized by status.

    export async function getUserMangaList(
    token: string,
    abortSignal?: AbortSignal,
    ): Promise<UserMediaList> {
    if (!token) {
    throw new Error("Access token required to fetch user manga list");
    }

    try {
    // Get the user's ID first
    const viewerId = await getAuthenticatedUserID(token, abortSignal);
    console.log("Successfully retrieved user ID:", viewerId);

    if (!viewerId) {
    throw new Error("Failed to get your AniList user ID");
    }

    // Fetch all manga lists using multiple chunks if needed
    return await fetchCompleteUserMediaList(viewerId, token, abortSignal);
    } catch (error: unknown) {
    console.error("Error fetching user manga list:", error);

    // Type guard to check if error is an object with specific properties
    if (error && typeof error === "object") {
    const errorObj = error as {
    status?: number;
    isRateLimited?: boolean;
    retryAfter?: number;
    message?: string;
    };

    // Check for direct rate limit errors
    const directRateLimitError = checkDirectRateLimitError(errorObj);
    if (directRateLimitError) {
    throw directRateLimitError;
    }

    // Check for rate limit mentions in error messages
    const messageBasisRateLimitError = checkRateLimitInMessage(errorObj);
    if (messageBasisRateLimitError) {
    throw messageBasisRateLimitError;
    }
    }

    throw error;
    }
    }