Skip to content

fix: improve pagination parser #12422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2024
Merged

fix: improve pagination parser #12422

merged 2 commits into from
Mar 5, 2024

Conversation

mtojek
Copy link
Member

@mtojek mtojek commented Mar 5, 2024

Related: #11795

This PR improves pagination logic to prevent HTTP 500s caused by PostgreSQL errors.

Before

URL: http://localhost:3000/api/v2/workspaces?limit=1&offset=1000000000000
Reply: {"message":"Internal error fetching workspaces.","detail":"pq: OFFSET must not be negative"}

URL: http://localhost:3000/api/v2/workspaces?limit=1000000000000&offset=-2
Reply: {"message":"Internal error fetching workspaces.","detail":"pq: OFFSET must not be negative"}

URL: http://localhost:3000/api/v2/workspaces?limit=1&offset=991000000000000
Reply: {"workspaces":[],"count":2} // This one works in a weird way :)

After

URL: http://localhost:3000/api/v2/workspaces?limit=1000000000000&offset=-2
Reply: {"message":"Query parameters have invalid values.","validations":[{"field":"limit","detail":"Query param \"limit\" must be a valid 32-bit positive integer (strconv.ParseInt: parsing \"1000000000000\": value out of range)"},{"field":"offset","detail":"Query param \"offset\" must be a valid 32-bit positive integer (value is negative)"}]}

URL: http://localhost:3000/api/v2/workspaces?limit=1&offset=2147483648
Reply: {"message":"Query parameters have invalid values.","validations":[{"field":"offset","detail":"Query param \"offset\" must be a valid 32-bit positive integer (strconv.ParseInt: parsing \"2147483648\": value out of range)"}]}

@mtojek mtojek self-assigned this Mar 5, 2024
@mtojek mtojek marked this pull request as ready for review March 5, 2024 10:24
@mtojek mtojek requested review from johnstcn and dannykopping March 5, 2024 10:24
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with nit

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mtojek mtojek enabled auto-merge (squash) March 5, 2024 13:55
@mtojek mtojek merged commit 3e99c03 into main Mar 5, 2024
@mtojek mtojek deleted the fix-negative-offset branch March 5, 2024 14:05
@github-actions github-actions bot locked and limited conversation to collaborators Mar 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants