Budibase/budibase · error · HTTPError

Invalid page query

Error message

Invalid page query

What it means

Thrown by sanitizePageQuery when the `page` query parameter is not a pure digit string. A missing or whitespace-only page falls back to 1; anything failing /^\d+$/ (e.g. 'two', '1.0', '0x1', '-1') is rejected with this 400 error.

Source

Thrown at packages/server/src/api/controllers/ai/agentRequests.ts:37

    throw new HTTPError("Invalid limit query", 400)
  }

  const parsedLimit = Number.parseInt(normalizedLimit, 10)
  if (parsedLimit < 1 || parsedLimit > 100) {
    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
  }

View on GitHub (pinned to a81a902e9a)

Solutions

  1. Send a plain positive integer, e.g. ?page=2
  2. Omit the page parameter to start at page 1
  3. Validate/coerce the page value client-side before building the URL
  4. Fix template code that stringifies undefined/null into the query

Example fix

// before
const url = `/requests?page=${currentPage}` // currentPage = undefined
// after
const url = `/requests?page=${parseInt(currentPage, 10) || 1}`
Defensive patterns

Strategy: validation

Validate before calling

function sanitizePage(page) {
  if (page === undefined || page === null || String(page).trim() === "") return 1
  const s = String(page).trim()
  if (!/^\d+$/.test(s)) throw new Error("page must be an integer")
  const n = parseInt(s, 10)
  if (n < 1) throw new Error("page must be greater than 0")
  return n
}
sanitizePage(searchParams.get("page"))

Type guard

function isPositiveIntegerString(v) {
  return typeof v === "string" && /^\d+$/.test(v) && parseInt(v, 10) >= 1
}

Try / catch

try {
  return await fetchAgentRequests(agentId, { page })
} catch (err) {
  if (err.status === 400 && err.message === "Invalid page query") {
    return fetchAgentRequests(agentId, { page: 1 })
  }
  throw err
}

Prevention

When it happens

Trigger: GET agent requests with ?page=first, ?page=1.0, ?page=-1, or page values interpolated from non-numeric variables such as 'null' or 'undefined' strings.

Common situations: Pagination components passing the raw string from an input box; array-index-based page variables that are undefined on first render; URLs shared with hand-edited page params; confusion between 0-indexed and 1-indexed pages leading to '0' (which passes regex but fails the >0 check).

Related errors


AI-assisted analysis of Budibase/budibase@a81a902e9a (2026-08-29). Data as JSON: /api/errors/abd4c21d0c1d7a92. Report an issue: GitHub.