Skip to content

Fix/nan pagination#30

Open
russo2100 wants to merge 2 commits into
profullstack:masterfrom
russo2100:fix/nan-pagination
Open

Fix/nan pagination#30
russo2100 wants to merge 2 commits into
profullstack:masterfrom
russo2100:fix/nan-pagination

Conversation

@russo2100

Copy link
Copy Markdown
Contributor
### Description
This PR resolves a critical pagination bug in the modules and reviews API routes (Issues #10 and #14) where invalid string inputs for `page` or

limit parameters caused the Supabase query to fail.

### Root Cause
Previously, calling `parseInt()` on a non-numeric string returned `NaN`. Since `Math.max(1, NaN)` evaluates to `NaN`, these invalid values were

propagating down to the Supabase query as .range(NaN, NaN), causing an exception.

### Changes Included
- **`apps/web/src/app/api/modules/route.ts`**: Replaced direct inline `parseInt` evaluation with a strict `Number.isNaN()` check. If the parsed value

is NaN, it now safely defaults to 1 for the page and 20 for the limit.
- apps/web/src/app/api/modules/[slug]/review/route.ts: Applied the same NaN validation and fallback logic for the review pagination.

### Impact
The API now properly handles malformed query parameters and safely defaults to standard pagination limits, preventing database crashes and improving

overall endpoint stability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant