different-ai/openwork · error · Error
Automation request failed (${result.response.status}).
Error message
Automation request failed (${result.response.status}). What it means
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.
Source
Thrown at ee/apps/den-web/app/(den)/dashboard/_components/automation-data.tsx:16
"use client";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import {
automationDetailSchema,
automationListSchema,
automationRunReceiptSchema,
automationRunSchema,
} from "@openwork/types/automations";
import type { CreateCloudAutomation, UpdateAutomation } from "@openwork/types/automations";
import { workflowArtifactSnapshotSchema } from "@openwork/types/workflows";
import { getErrorMessage, requestJson } from "../../_lib/den-flow";
async function payload(path: string, init: RequestInit = { method: "GET" }) {
const result = await requestJson(path, init, 170_000);
if (!result.response.ok) throw new Error(getErrorMessage(result.payload, `Automation request failed (${result.response.status}).`));
return result.payload;
}
export function useAutomations() {
return useQuery({ queryKey: ["automations", "list"], queryFn: async () => automationListSchema.parse(await payload("/v1/automations?limit=100")) });
}
export function useAutomation(automationId: string | null) {
return useQuery({
queryKey: ["automations", "detail", automationId],
queryFn: async () => automationDetailSchema.parse(await payload(`/v1/automations/${encodeURIComponent(automationId ?? "")}`)),
enabled: Boolean(automationId),
});
}
export function useAutomationRuns(automationId: string | null) {
return useQuery({
queryKey: ["automations", "runs", automationId],View on GitHub (pinned to 2b7df46e8a)
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.
Example fix
// before
if (!result.response.ok) throw new Error(getErrorMessage(result.payload, `Automation request failed (${result.response.status}).`));
// after
if (result.response.status === 401) throw new Error("Session expired — please sign in again.");
if (!result.response.ok) throw new Error(getErrorMessage(result.payload, `Automation request failed (${result.response.status}).`)); Defensive patterns
Strategy: retry
Validate before calling
// Pre-flight session check before running automation queries
const session = await fetch("/api/session", { method: "HEAD" });
if (!session.ok) { redirectToSignIn(); } Type guard
function isAutomationList(v: unknown): v is { items: unknown[] } {
return typeof v === "object" && v !== null && "items" in v && Array.isArray((v as {items:unknown}).items);
} Try / catch
try {
const automations = await payload("/v1/automations?limit=100");
} catch (err) {
const status = /\((\d{3})\)/.exec(err instanceof Error ? err.message : "")?.[1];
if (status === "401") redirectToSignIn();
else if (status === "429" || status?.startsWith("5")) scheduleRetry();
else showToast(err instanceof Error ? err.message : "Automation request failed");
} Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- Failed to load connection details (${response.status}).
- Billing lookup failed (${response.status}).
- Failed to start OAuth (${response.status}).
- CUA API error ${response.status}: ${errorText.slice(0, 300)}
- latest-mac.yml is missing artifact path/url.
AI-assisted analysis of different-ai/openwork@2b7df46e8a (2026-09-01).
Data as JSON: /api/errors/300abecdd1013c2a.
Report an issue: GitHub.