{"record":{"id":"87d4542af735d11e","repo":"different-ai/openwork","slug":"workflow-action-failed-response-status","errorCode":null,"errorMessage":"Workflow action failed (${response.status}).","messagePattern":"Workflow action failed \\((.+?)\\)\\.","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ee/apps/den-web/app/(den)/dashboard/_components/workflow-detail-data.tsx","lineNumber":53,"sourceCode":"    throw new Error(\"Workflow response was incomplete.\");\n  }\n  return {\n    workflow: {\n      type: \"workflow\", id: workflow.id, plugin, name: workflow.name,\n      description: typeof workflow.description === \"string\" ? workflow.description : null,\n      role, state, resultState,\n      latestSuccessfulAt: typeof workflow.latestSuccessfulAt === \"string\" ? workflow.latestSuccessfulAt : null,\n      viewState, activeViewTitle: typeof workflow.activeViewTitle === \"string\" ? workflow.activeViewTitle : null,\n      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(","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/different-ai/openwork/blob/2b7df46e8ae1517d64c896c7793d2d52ec845669/ee/apps/den-web/app/(den)/dashboard/_components/workflow-detail-data.tsx#L35-L71","documentation":"mutationJson performs POST/PUT workflow mutations (activate/retire artifact view) via requestJson and throws 'Workflow action failed (STATUS).' when response.ok is false, preferring a server-provided error message from getErrorMessage(payload, fallback). It is the single choke point for all workflow mutation calls in this module.","triggerScenarios":"Any POST/PUT to a workflow view endpoint returning a non-2xx: 401 expired session, 403 insufficient role, 404 unknown workflow/view id, 409 conflicting view state, 422 invalid view payload, 5xx Den server error, or a timeout at the 15s requestJson limit.","commonSituations":"Session token expired mid-edit, user role downgraded below what the mutation requires, activating a view on a workflow that was concurrently retired, self-hosted Den behind a misconfigured proxy returning 502, or the 15s timeout firing on a slow network.","solutions":["Read the response.status and any message in the JSON payload to identify the exact server rejection cause.","Re-authenticate if status is 401 (sign-in flow refreshes the Den session).","Verify the current member's role permits activating/retiring views (owner/admin).","Confirm the workflow and view ids still exist; refresh the detail query.","Retry after backing off if status >= 500 or the request timed out."],"exampleFix":"// before\nconst { response, payload } = await requestJson(path, { method }, 15_000);\nif (!response.ok) throw new Error(getErrorMessage(payload, `Workflow action failed (${response.status}).`));\n// after (caller-side retry on transient failures)\ntry { await mutationJson(path, \"POST\"); }\ncatch (e) { if (isTransient(e)) await retryWithBackoff(() => mutationJson(path, \"POST\")); else throw e; }","handlingStrategy":"try-catch","validationCode":"if (!workflowId || !viewId) throw new Error(\"Missing workflow/view id before mutation\");","typeGuard":"null","tryCatchPattern":"try {\n  await mutationJson(`/v1/workflows/${id}/views/${viewId}`, \"POST\");\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith(\"Workflow action failed\")) {\n    if (/\\(401\\)/.test(e.message)) await reauth();\n    else if (/\\((5\\d\\d)\\)/.test(e.message)) scheduleRetry();\n    else showToast(e.message);\n  } else throw e;\n}","preventionTips":["Refresh sessions before long editing sessions.","Check role/permission flags before enabling mutation buttons.","Re-fetch detail before mutating to confirm the view still exists.","Add backoff retry for 5xx only."],"tags":["http","api","mutation","network"],"backgroundTag":"http-request-failed","analyzedSha":"2b7df46e8ae1517d64c896c7793d2d52ec845669","analyzedAt":"2026-09-01T07:59:23.713Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}