Skip to content

fetchTmdbList initializes totalPages to 999 with no guard against a missing first-response value #98

@ooloth

Description

@ooloth

Why

fetchTmdbList sets totalPages = 999 as a sentinel before the first API response, then updates it from data.total_pages. If the first response is missing or invalid total_pages, the sentinel is never replaced and the loop issues up to 999 API calls — silently hammering the TMDB API.

Current state

io/tmdb/fetchTmdbList.ts lines 51 and 85: let totalPages = 999 initialised before the loop; totalPages = data.total_pages after the first response. If data.total_pages is undefined or zero, the sentinel value drives the loop for its full 999 iterations with no guard.

Ideal state

  • After the first response is received, totalPages is validated to be a finite positive integer before the loop condition re-evaluates.
  • A missing or invalid total_pages in the first response produces a descriptive error and stops the loop rather than triggering up to 999 unintended requests.

Starting points

  • io/tmdb/fetchTmdbList.ts — lines 51 and 85, the totalPages initialization and the update assignment

QA plan

  1. Mock a TMDB API response with total_pages: undefined — expect the loop stops after the first request and produces a descriptive error rather than continuing for 999 iterations.
  2. Mock a response with total_pages: 3 — expect the loop runs exactly 3 times.

Done when

fetchTmdbList validates total_pages on the first response and never makes more than the declared number of pages of requests.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions