{"record":{"id":"300abecdd1013c2a","repo":"different-ai/openwork","slug":"automation-request-failed-result-response-statu","errorCode":null,"errorMessage":"Automation request failed (${result.response.status}).","messagePattern":"Automation request failed \\((.+?)\\)\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/automation-data.tsx","lineNumber":16,"sourceCode":"\"use client\";\n\nimport { useMutation, useQuery, useQueryClient } from \"@tanstack/react-query\";\nimport {\n  automationDetailSchema,\n  automationListSchema,\n  automationRunReceiptSchema,\n  automationRunSchema,\n} from \"@openwork/types/automations\";\nimport type { CreateCloudAutomation, UpdateAutomation } from \"@openwork/types/automations\";\nimport { workflowArtifactSnapshotSchema } from \"@openwork/types/workflows\";\nimport { getErrorMessage, requestJson } from \"../../_lib/den-flow\";\n\nasync function payload(path: string, init: RequestInit = { method: \"GET\" }) {\n  const result = await requestJson(path, init, 170_000);\n  if (!result.response.ok) throw new Error(getErrorMessage(result.payload, `Automation request failed (${result.response.status}).`));\n  return result.payload;\n}\n\nexport function useAutomations() {\n  return useQuery({ queryKey: [\"automations\", \"list\"], queryFn: async () => automationListSchema.parse(await payload(\"/v1/automations?limit=100\")) });\n}\n\nexport function useAutomation(automationId: string | null) {\n  return useQuery({\n    queryKey: [\"automations\", \"detail\", automationId],\n    queryFn: async () => automationDetailSchema.parse(await payload(`/v1/automations/${encodeURIComponent(automationId ?? \"\")}`)),\n    enabled: Boolean(automationId),\n  });\n}\n\nexport function useAutomationRuns(automationId: string | null) {\n  return useQuery({\n    queryKey: [\"automations\", \"runs\", automationId],","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/automation-data.tsx#L1-L34","documentation":"payload() in automation-data.tsx is the shared fetch wrapper for all automation queries. requestJson performs the HTTP call (170s timeout) and if response.ok is false, the error is thrown using the server-provided error message or this generic fallback including the HTTP status. It means the automation API endpoint returned a non-2xx response.","triggerScenarios":"GET /v1/automations?limit=100 or other automation endpoints return 401 (expired Den session), 403 (not a member of the org), 404 (server without automations routes), 429 (rate limited), or 5xx (server error).","commonSituations":"Session cookie expired mid-use; user switched orgs and the token lacks access; self-hosted server predates the automations feature (404); backend deploy in progress causing 502/503.","solutions":["Read the status code in the message and the server error body; handle 401 by re-authenticating (sign in again).","Confirm the Den server version supports /v1/automations routes.","Retry the query if it was a transient 5xx/429; React Query will retry per its config.","Check org membership/permissions if the status is 403."],"exampleFix":"// before\nif (!result.response.ok) throw new Error(getErrorMessage(result.payload, `Automation request failed (${result.response.status}).`));\n// after\nif (result.response.status === 401) throw new Error(\"Session expired — please sign in again.\");\nif (!result.response.ok) throw new Error(getErrorMessage(result.payload, `Automation request failed (${result.response.status}).`));","handlingStrategy":"retry","validationCode":"// Pre-flight session check before running automation queries\nconst session = await fetch(\"/api/session\", { method: \"HEAD\" });\nif (!session.ok) { redirectToSignIn(); }","typeGuard":"function isAutomationList(v: unknown): v is { items: unknown[] } {\n  return typeof v === \"object\" && v !== null && \"items\" in v && Array.isArray((v as {items:unknown}).items);\n}","tryCatchPattern":"try {\n  const automations = await payload(\"/v1/automations?limit=100\");\n} catch (err) {\n  const status = /\\((\\d{3})\\)/.exec(err instanceof Error ? err.message : \"\")?.[1];\n  if (status === \"401\") redirectToSignIn();\n  else if (status === \"429\" || status?.startsWith(\"5\")) scheduleRetry();\n  else showToast(err instanceof Error ? err.message : \"Automation request failed\");\n}","preventionTips":["Configure React Query retries with backoff for 5xx/429 only.","Handle 401 globally (interceptor) by redirecting to sign-in.","Feature-detect /v1/automations availability on older self-hosted servers.","Surface the HTTP status in user-facing messages for faster triage."],"tags":["network","http-error","automations"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}