{"record":{"id":"e6273084f61fc738","repo":"wandb/openui","slug":"body-error-message","errorCode":null,"errorMessage":"body.error.message","messagePattern":"body\\.error\\.message","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/api/openui.ts","lineNumber":34,"sourceCode":"\nconst API_HOST = (import.meta.env.VITE_API_HOST ?? '/v1') as string\n\nexport async function share(id: string, item: ItemWrapper, versionIdx: number) {\n\tconst r = await fetch(`${API_HOST}/share/${id}`, {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json'\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tprompt: item.prompt(versionIdx),\n\t\t\thtml: item.pureHTML(versionIdx),\n\t\t\tname: item.name,\n\t\t\temoji: item.emoji\n\t\t})\n\t})\n\tif (r.status !== 201) {\n\t\tconst body = (await r.json()) as ErrorBody\n\t\tthrow new Error(body.error.message)\n\t}\n}\n\nexport async function voteRequest(\n\tvote: boolean,\n\titem: ItemWrapper,\n\tversionIdx: number\n) {\n\tconst r = await fetch(`${API_HOST}/vote`, {\n\t\tmethod: 'POST',\n\t\theaders: {\n\t\t\t'Content-Type': 'application/json'\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\tprompt: item.prompt(versionIdx),\n\t\t\thtml: item.pureHTML(versionIdx),\n\t\t\tname: item.name,\n\t\t\temoji: item.emoji,","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/wandb/openui/blob/42d7ab4ab6650433486dfb12eb3783c393a3e475/frontend/src/api/openui.ts#L16-L52","documentation":"share() fetches POST /share to create a public share link and expects HTTP 201. On any other status it parses the response JSON as ErrorBody and rethrows the server's error.message as a plain Error. This surfaces backend validation/session failures to the ShareDialog caller.","triggerScenarios":"Any non-201 response from POST ${API_HOST}/share when sharing a history item (e.g. session expired, server 500, invalid item payload).","commonSituations":"User's auth session cookie expired or missing; backend rejected the share payload; API server down and a proxy returns an HTML error page that fails r.json().","solutions":["Ensure the user has an active session (call auth/login) before calling share().","Check the browser network tab for the actual status/body of POST /share and fix the server-side cause.","Wrap share() in try/catch in ShareDialog and surface the message to the user.","If r.json() itself throws on non-JSON bodies, use r.text() first as a fallback."],"exampleFix":"// before\nconst body = (await r.json()) as ErrorBody\nthrow new Error(body.error.message)\n// after\nlet message = `Share failed with status ${r.status}`\ntry {\n  const body = (await r.json()) as ErrorBody\n  if (body?.error?.message) message = body.error.message\n} catch {}\nthrow new Error(message)","handlingStrategy":"try-catch","validationCode":"if (!navigator.cookieEnabled || !document.cookie) console.warn('No session cookie — share() will likely 401')","typeGuard":"function isErrorBody(b: unknown): b is ErrorBody {\n  return typeof b === 'object' && b !== null && 'error' in b &&\n    typeof (b as ErrorBody).error?.message === 'string'\n}","tryCatchPattern":"try {\n  await share(item)\n} catch (e) {\n  showError(e instanceof Error ? e.message : 'Sharing failed — please log in again')\n}","preventionTips":["Verify an active session before share operations","Always parse error bodies defensively (non-JSON possible)","Surface server messages to the UI instead of failing silently"],"tags":["http","api","typescript","share"],"backgroundTag":"http-error-response-unhandled","analyzedSha":"42d7ab4ab6650433486dfb12eb3783c393a3e475","analyzedAt":"2026-09-01T05:00:32.200Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}