{"record":{"id":"6a6d0fbf75161ed6","repo":"QuantumNous/new-api","slug":"api-returned-error","errorCode":null,"errorMessage":"API returned error","messagePattern":"API returned error","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"web/src/hooks/use-system-config.ts","lineNumber":111,"sourceCode":"  }\n\n  return {\n    systemName: data.system_name || DEFAULT_SYSTEM_NAME,\n    logo: data.logo || DEFAULT_LOGO,\n    footerHtml: data.footer_html,\n    demoSiteEnabled: data.demo_site_enabled,\n    displayTokenStatEnabled: data.display_token_stat_enabled,\n    currency,\n  }\n}\n\n// Fetch system config from API\nasync function fetchSystemConfig(): Promise<Partial<SystemConfig>> {\n  const response = await fetch('/api/status')\n  if (!response.ok) throw new Error('Failed to fetch status')\n\n  const data: StatusApiResponse = await response.json()\n  if (!data.success) throw new Error('API returned error')\n\n  return mapStatusDataToConfig(data.data)\n}\n\n// Preload image and return cleanup function\nfunction preloadImage(\n  src: string,\n  onLoad: () => void,\n  onError: () => void\n): () => void {\n  const img = new Image()\n  img.onload = onLoad\n  img.onerror = onError\n  img.src = src\n\n  return () => {\n    img.onload = null\n    img.onerror = null","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/QuantumNous/new-api/blob/e2c7aa7b102c2075eae2377df3508658d45e88dc/web/src/hooks/use-system-config.ts#L93-L129","documentation":"Thrown by fetchSystemConfig in use-system-config when /api/status answered HTTP 200 but the JSON envelope has success:false. This means the Go backend itself reported an operational failure (its unified response wrapper), not a transport problem. The app falls back to default system name/logo/flags.","triggerScenarios":"GET /api/status returns 200 with {success:false,...}: backend panic recovered into an error envelope, maintenance mode, or an internal error computing status data (e.g. options/cache failure).","commonSituations":"Backend started with a broken database/Redis connection so status assembly fails; a plugin/option load error; deployment where the status handler depends on an uninitialized subsystem.","solutions":["curl the /api/status endpoint and read the envelope's message field — the code drops it; capture it to find the backend cause.","Check backend (new-api Go) logs for the error returned by the status controller.","Fix the underlying backend issue (DB/Redis connectivity, options table) and reload.","Consider surfacing response message in the thrown error to speed future diagnosis."],"exampleFix":"// before\nconst data: StatusApiResponse = await response.json()\nif (!data.success) throw new Error('API returned error')\n\n// after\nconst data: StatusApiResponse = await response.json()\nif (!data.success) throw new Error(data.message || 'API returned error')","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function isStatusSuccess(data: unknown): data is { success: true; data: StatusApiResponse['data'] } {\n  return typeof data === 'object' && data !== null && (data as any).success === true\n}","tryCatchPattern":"try {\n  const config = await fetchSystemConfig()\n} catch (error) {\n  // both 'Failed to fetch status' and 'API returned error' map to default config;\n  // log error and continue — never block app boot on status\n}","preventionTips":["Monitor backend health so /api/status does not fail operationally","Surface data.message from the envelope in dev builds to speed root-cause"],"tags":["system-config","api-envelope","backend-error"],"backgroundTag":null,"analyzedSha":"e2c7aa7b102c2075eae2377df3508658d45e88dc","analyzedAt":"2026-08-15T10:35:18.111Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}