Budibase/budibase · error · HTTPError
Page query must be greater than 0
Error message
Page query must be greater than 0
What it means
Thrown by sanitizePageQuery when the page value is numeric but less than 1. Pages are 1-indexed; ?page=0 (or a negative digit string is impossible here since '-' fails the regex, but 0 passes it) reaches the parsedPage < 1 check and is rejected with this 400 error.
Source
Thrown at packages/server/src/api/controllers/ai/agentRequests.ts:42
throw new HTTPError("Limit query must be between 1 and 100", 400)
}
return parsedLimit
}
const sanitizePageQuery = (page?: string): number => {
const normalizedPage = page?.trim()
if (!normalizedPage) {
return 1
}
if (!/^\d+$/.test(normalizedPage)) {
throw new HTTPError("Invalid page query", 400)
}
const parsedPage = Number.parseInt(normalizedPage, 10)
if (parsedPage < 1) {
throw new HTTPError("Page query must be greater than 0", 400)
}
return parsedPage
}
const sanitizeStatusQuery = (
status?: string
): AgentRequestStatus | undefined => {
const normalizedStatus = status?.trim()
if (!normalizedStatus) {
return undefined
}
if (
!AGENT_REQUEST_STATUSES.includes(normalizedStatus as AgentRequestStatus)
) {
throw new HTTPError("Invalid status query", 400)
}View on GitHub (pinned to a81a902e9a)
Solutions
- Use ?page=1 for the first page (pages are 1-indexed)
- Convert 0-indexed page variables: page = zeroIndex + 1
- Clamp client-side: Math.max(1, page)
- Omit the page parameter entirely to default to page 1
Example fix
// before
const url = `/requests?page=${pageIndex}` // pageIndex = 0
// after
const url = `/requests?page=${pageIndex + 1}` Defensive patterns
Strategy: validation
Validate before calling
function normalizePage(page) {
const n = Number.parseInt(String(page), 10)
return Number.isNaN(n) || n < 1 ? 1 : n
}
normalizePage(searchParams.get("page")) Type guard
function isPageNumber(v) {
return typeof v === "number" && Number.isInteger(v) && v >= 1
} Try / catch
try {
return await fetchAgentRequests(agentId, { page })
} catch (err) {
if (err.status === 400 && err.message === "Page query must be greater than 0") {
return fetchAgentRequests(agentId, { page: 1 })
}
throw err
} Prevention
- Remember pages are 1-indexed; map 0-indexed counters with +1
- Guard division-based page math (offset/limit) so it never yields 0 sent as page
- Start pagination loops at page 1
- Clamp with Math.max(1, page) before sending
When it happens
Trigger: GET agent requests with ?page=0. This is the only digit string that passes /^\d+$/ but fails the range check for pages.
Common situations: 0-indexed pagination logic being sent directly to a 1-indexed API; loop initializers starting at i=0 for page params; clients computing page = offset / limit where offset is 0.
Related errors
- Invalid bookmark query
- Invalid limit query
- Limit query must be between 1 and 100
- Invalid limit query
- Limit query must be between 1 and 100
AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29).
Data as JSON: /api/errors/4321bdcd90324d0c.
Report an issue: GitHub.