{"record":{"id":"7e4724a8823c1b28","repo":"Budibase/budibase","slug":"invalid-status-query","errorCode":null,"errorMessage":"Invalid status query","messagePattern":"Invalid status query","errorType":"http","errorClass":"HTTPError","httpStatus":400,"severity":"error","filePath":"packages/server/src/api/controllers/ai/agentRequests.ts","lineNumber":59,"sourceCode":"  if (parsedPage < 1) {\n    throw new HTTPError(\"Page query must be greater than 0\", 400)\n  }\n\n  return parsedPage\n}\n\nconst sanitizeStatusQuery = (\n  status?: string\n): AgentRequestStatus | undefined => {\n  const normalizedStatus = status?.trim()\n  if (!normalizedStatus) {\n    return undefined\n  }\n\n  if (\n    !AGENT_REQUEST_STATUSES.includes(normalizedStatus as AgentRequestStatus)\n  ) {\n    throw new HTTPError(\"Invalid status query\", 400)\n  }\n\n  return normalizedStatus as AgentRequestStatus\n}\n\nexport async function fetchAgentRequests(\n  ctx: UserCtx<void, FetchAgentRequestsResponse>\n) {\n  const { limit, page, status } = ctx.query as Record<string, string>\n  const resolvedLimit = sanitizeLimitQuery(limit)\n  const resolvedPage = sanitizePageQuery(page)\n  const resolvedStatus = sanitizeStatusQuery(status)\n  const [requests, summary] = await Promise.all([\n    sdk.ai.agentRequests.fetchRequests({\n      limit: resolvedLimit,\n      page: resolvedPage,\n      status: resolvedStatus,\n    }),","sourceCodeStart":41,"sourceCodeEnd":77,"githubUrl":"https://github.com/Budibase/budibase/blob/a81a902e9a8fe55b467d106765f6638f12e35c49/packages/server/src/api/controllers/ai/agentRequests.ts#L41-L77","documentation":"Thrown by sanitizeStatusQuery when the `status` query parameter is not a member of AGENT_REQUEST_STATUSES. The value is checked against the allowed AgentRequestStatus enum; unknown statuses are rejected with this 400 error rather than silently returning no results.","triggerScenarios":"GET agent requests with ?status=FAILED, ?status=complete, ?status=cancelled or any other value not exactly matching an entry in AGENT_REQUEST_STATUSES (case-sensitive membership check).","commonSituations":"Frontend filter dropdowns whose options drifted from the backend enum; users pasting status text with different casing; older client versions using renamed status values after an API change; generic UI components passing 'all' or 'any' pseudo-values.","solutions":["Use one of the exact AGENT_REQUEST_STATUSES values (check the AgentRequestStatus type in the codebase for the list)","Match casing exactly as defined by the enum","Remove the status filter to fetch all statuses","Update client filter options to stay in sync with the server enum after renames"],"exampleFix":"// before\n?status=Complete\n// after\n?status=complete // must match AgentRequestStatus exactly","handlingStrategy":"validation","validationCode":"const AGENT_REQUEST_STATUSES = [\"success\", \"error\"] // check AgentRequestStatus in @budibase/types for exact values\nfunction validateStatus(status) {\n  if (status !== undefined && !AGENT_REQUEST_STATUSES.includes(status)) {\n    throw new Error(`status must be one of: ${AGENT_REQUEST_STATUSES.join(\", \")}`)\n  }\n  return status\n}\nvalidateStatus(searchParams.get(\"status\"))","typeGuard":"function isAgentRequestStatus(v) {\n  return AGENT_REQUEST_STATUSES.includes(v)\n}","tryCatchPattern":"try {\n  return await fetchAgentRequests(agentId, { status })\n} catch (err) {\n  if (err.status === 400 && err.message === \"Invalid status query\") {\n    return fetchAgentRequests(agentId, { status: undefined }) // no filter\n  }\n  throw err\n}","preventionTips":["Import the AgentRequestStatus type/enum from @budibase/types instead of hardcoding strings","Keep client filter dropdown options generated from the same enum the server uses","Treat status comparisons as case-sensitive","Handle 'all' pseudo-values client-side by omitting the status param"],"tags":["validation","http-400","query-params","enum"],"backgroundTag":"invalid-query-parameter","analyzedSha":"a81a902e9a8fe55b467d106765f6638f12e35c49","analyzedAt":"2026-08-29T01:03:10.972Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}