{"record":{"id":"e295f1017a84fc37","repo":"different-ai/openwork","slug":"failed-to-load-workflow-response-status","errorCode":null,"errorMessage":"Failed to load Workflow (${response.status}).","messagePattern":"Failed to load Workflow \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/workflow-detail-data.tsx","lineNumber":62,"sourceCode":"      automationCount: workflow.automationCount, source: { kind: sourceKind },\n    },\n    script: workflowDetailSchema.parse(value.script),\n    views: value.views.map((view) => generatedArtifactViewSchema.parse(view)),\n  };\n}\n\nasync function mutationJson(path: string, method: \"POST\" | \"PUT\") {\n  const { response, payload } = await requestJson(path, { method }, 15_000);\n  if (!response.ok) throw new Error(getErrorMessage(payload, `Workflow action failed (${response.status}).`));\n  return payload;\n}\n\nexport function useWorkflowLibraryDetail(workflowId: string) {\n  return useQuery({\n    queryKey: [\"workflow\", workflowId],\n    queryFn: async () => {\n      const { response, payload } = await requestJson(`/v1/workflows/${encodeURIComponent(workflowId)}`, { method: \"GET\" }, 15_000);\n      if (!response.ok) throw new Error(getErrorMessage(payload, `Failed to load Workflow (${response.status}).`));\n      return parseWorkflowDetail(payload);\n    },\n  });\n}\n\nexport function useActivateArtifactView(workflowId: string) {\n  const client = useQueryClient();\n  return useMutation({\n    mutationFn: async ({ viewId, revisionId }: { viewId: string; revisionId: string }) => generatedArtifactViewSchema.parse(await mutationJson(\n      `/v1/artifact-views/${encodeURIComponent(viewId)}/revisions/${encodeURIComponent(revisionId)}/activate`,\n      \"POST\",\n    )),\n    onSuccess: async () => client.invalidateQueries({ queryKey: [\"workflow\", workflowId] }),\n  });\n}\n\nexport function useRetireArtifactView(workflowId: string) {\n  const client = useQueryClient();","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/workflow-detail-data.tsx#L44-L80","documentation":"useWorkflowLibraryDetail is a React Query hook that GETs /v1/workflows/:id and throws 'Failed to load Workflow (STATUS).' when the response is not ok, before parsing via parseWorkflowDetail. The error surfaces through the query's error state so components can render a load-failure message.","triggerScenarios":"GET /v1/workflows/{encodeURIComponent(id)} returns non-2xx: 404 for a deleted or foreign-org workflow id, 401 unauthenticated, 403 no access, 5xx Den backend failure, or requestJson's 15s timeout.","commonSituations":"Navigating to a workflow detail page for a workflow deleted in another tab, stale deep-link id after org switch, session expiry, Den server restart or proxy 502/504, or a workflow id containing characters that break routing if not encoded.","solutions":["Check response.status in the query error and the payload message from getErrorMessage.","If 401/403, re-authenticate or verify the user belongs to the workflow's organization.","If 404, confirm the workflow id is current; refresh the workflow library list.","Retry the query (React Query refetch) if the failure was 5xx or a timeout.","Verify the Den backend/proxy is healthy if all workflows fail to load."],"exampleFix":"// before\nconst detail = useWorkflowLibraryDetail(workflowId);\n// after (caller handles error state)\nconst detail = useWorkflowLibraryDetail(workflowId);\nif (detail.isError) return <ErrorNotice message={detail.error.message} onRetry={detail.refetch} />;","handlingStrategy":"try-catch","validationCode":"if (!workflowId) throw new Error(\"workflowId is required\");","typeGuard":"null","tryCatchPattern":"const q = useWorkflowLibraryDetail(id);\nif (q.isError) {\n  const msg = q.error instanceof Error ? q.error.message : \"Failed to load Workflow.\";\n  if (/\\(404\\)/.test(msg)) navigateBackToList();\n  else return <ErrorNotice message={msg} onRetry={q.refetch} />;\n}","preventionTips":["Always encode the workflow id with encodeURIComponent.","React to 404 by refreshing the library list rather than retrying forever.","Set sensible React Query retry rules (no retry on 4xx).","Re-authenticate when 401 errors appear."],"tags":["http","react-query","network","data-loading"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}