{"record":{"id":"d01a864a40a307fc","repo":"mui/material-ui","slug":"failed-to-open-in-mui-chat","errorCode":null,"errorMessage":"Failed to open in MUI Chat","messagePattern":"Failed to open in MUI Chat","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages-internal/core-docs/src/Demo/sandbox/MuiChat.ts","lineNumber":86,"sourceCode":"        const response = await fetch(`${baseUrl}/v1/public/chat/open`, {\n          method: 'POST',\n          headers: {\n            'Content-Type': 'application/json',\n          },\n          body: JSON.stringify({\n            name: demoData.title,\n            description: document.title,\n            files,\n            type: 'mui-docs',\n            package: {\n              name: primaryPackage,\n              version: dependencies[primaryPackage] || 'latest',\n            },\n          }),\n        });\n\n        if (!response.ok) {\n          throw new Error('Failed to open in MUI Chat');\n        }\n\n        const data = await response.json();\n        window.open(data.nextUrl, '_blank');\n      } catch (error) {\n        console.error('Error opening MUI Chat:', error);\n        throw error;\n      }\n    },\n  };\n}\n","sourceCodeStart":68,"sourceCodeEnd":98,"githubUrl":"https://github.com/mui/material-ui/blob/bdc96df2cb530fcdd60a7a7aabe37f610ce0f0a5/packages-internal/core-docs/src/Demo/sandbox/MuiChat.ts#L68-L98","documentation":"Thrown after the POST to `${baseUrl}/v1/public/chat/open` returns a non-2xx status. The helper already validated the base URL exists; this error means the Chat backend was reachable but rejected the request (auth, payload, rate limit, or upstream failure). The outer catch logs the response detail and re-throws so the UI can surface the failure.","triggerScenarios":"Clicking 'Open in MUI Chat' when the Chat service is down, returns 4xx for an invalid payload (e.g. missing primaryPackage), returns 401/403 due to missing auth, or 5xx during an incident; also triggered by transient network errors that produce an ok=false response.","commonSituations":"MUI Chat backend outage; preview/staging endpoint that requires auth headers the docs client does not send; demo with a productId that has no package mapping so the payload is malformed.","solutions":["Retry the click after a short wait — most failures are transient backend issues.","Check browser DevTools Network tab for the actual status code on /v1/public/chat/open; 4xx points to a payload/config problem, 5xx to a backend problem.","Use the CodeSandbox or StackBlitz open button as a fallback while Chat is unavailable.","If you operate the Chat backend, inspect its logs for the correlating request and verify the route and auth."],"exampleFix":"// before\nconst response = await fetch(`${baseUrl}/v1/public/chat/open`, {...});\nif (!response.ok) throw new Error('Failed to open in MUI Chat');\n// after — surface the status/body for diagnosis\nif (!response.ok) throw new Error(`Failed to open in MUI Chat (HTTP ${response.status}): ${await response.text()}`);","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"async function openChatWithRetry(payload, { retries = 2 } = {}) {\n  for (let attempt = 0; ; attempt++) {\n    try {\n      const res = await fetch(`${baseUrl}/v1/public/chat/open`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) });\n      if (res.ok) return res.json();\n      if (res.status >= 500 && attempt < retries) { await new Promise(r => setTimeout(r, 1000 * (attempt + 1))); continue; }\n      throw new Error(`Failed to open in MUI Chat (HTTP ${res.status})`);\n    } catch (e) {\n      if (attempt < retries) continue;\n      throw e;\n    }\n  }\n}","preventionTips":["Show a fallback (CodeSandbox/StackBlitz) in the UI when Chat returns non-2xx.","Surface the status code and response body in the re-thrown error for faster diagnosis.","Monitor the Chat endpoint uptime separately so docs editors know when to expect failures."],"tags":["network","docs-infra","runtime","api"],"backgroundTag":null,"analyzedSha":"bdc96df2cb530fcdd60a7a7aabe37f610ce0f0a5","analyzedAt":"2026-08-12T22:59:56.717Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}