DayuanJiang/next-ai-draw-io · error · Error

Request failed (${res.status})

Error message

Request failed (${res.status})

What it means

Generic HTTP failure raised by adminFetch when the server responds with a non-2xx status and the response body contains no `error` field. It is a catch-all wrapper for all admin API calls (settings, providers data fetching) in the admin panel.

Source

Thrown at app/[lang]/admin/admin-shared.ts:62

export interface EnvProvider {
    name: string
    provider: ProviderName
    models: string[]
    isDefault: boolean
}

export async function adminFetch(path: string, pw: string, init?: RequestInit) {
    const res = await fetch(getApiEndpoint(path), {
        ...init,
        headers: {
            ...init?.headers,
            "x-admin-password": pw,
            ...(init?.body ? { "Content-Type": "application/json" } : {}),
        },
    })
    const data = await res.json().catch(() => ({}))
    if (!res.ok) {
        throw new Error(data.error || `Request failed (${res.status})`)
    }
    return data
}

View on GitHub (pinned to 155ef4f7ac)

Solutions

  1. Verify ADMIN_PASSWORD is set and the admin password entered matches it
  2. Check the server logs for the underlying route error behind the non-2xx status
  3. Retry after the dev/prod server is fully compiled and running
  4. Inspect the raw response (curl with the x-admin-password header) to see body/status detail

Example fix

// before
const data = await adminFetch('/api/admin/settings', pw)

// after
const data = await adminFetch('/api/admin/settings', pw).catch((e) => {
  console.error('admin fetch failed:', e.message)
  return null
})
if (!data) return <p>Failed to load settings — check admin password/server logs.</p>
Defensive patterns

Strategy: try-catch

Validate before calling

const pw = getAdminPassword()
if (!pw) throw new Error('Admin password required before fetching')

Try / catch

try {
  const data = await adminFetch(url, pw, init)
} catch (e) {
  // e.message is either server 'error' field or 'Request failed (status)'
  if (/\(401\)|\(403\)/.test((e as Error).message)) redirect('/admin/login')
  else showError((e as Error).message)
}

Prevention

When it happens

Trigger: Any admin page fetch (data/[settingsData, providersData] hooks) hitting an admin route that returns 4xx/5xx without a JSON error body, e.g. 401 wrong admin password, 500 server crash, or a route returning plain text.

Common situations: Wrong or missing x-admin-password header, expired admin session, Next.js server not fully started, or an admin API route throwing before returning structured JSON.

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


AI-assisted analysis of DayuanJiang/next-ai-draw-io@155ef4f7ac (2026-08-27). Data as JSON: /api/errors/0072aae062516586. Report an issue: GitHub.