wandb/openui · error · Error

body.error.message

Error message

body.error.message

What it means

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.

Source

Thrown at frontend/src/api/openui.ts:34

const API_HOST = (import.meta.env.VITE_API_HOST ?? '/v1') as string

export async function share(id: string, item: ItemWrapper, versionIdx: number) {
	const r = await fetch(`${API_HOST}/share/${id}`, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify({
			prompt: item.prompt(versionIdx),
			html: item.pureHTML(versionIdx),
			name: item.name,
			emoji: item.emoji
		})
	})
	if (r.status !== 201) {
		const body = (await r.json()) as ErrorBody
		throw new Error(body.error.message)
	}
}

export async function voteRequest(
	vote: boolean,
	item: ItemWrapper,
	versionIdx: number
) {
	const r = await fetch(`${API_HOST}/vote`, {
		method: 'POST',
		headers: {
			'Content-Type': 'application/json'
		},
		body: JSON.stringify({
			prompt: item.prompt(versionIdx),
			html: item.pureHTML(versionIdx),
			name: item.name,
			emoji: item.emoji,

View on GitHub (pinned to 42d7ab4ab6)

Solutions

  1. Ensure the user has an active session (call auth/login) before calling share().
  2. Check the browser network tab for the actual status/body of POST /share and fix the server-side cause.
  3. Wrap share() in try/catch in ShareDialog and surface the message to the user.
  4. If r.json() itself throws on non-JSON bodies, use r.text() first as a fallback.

Example fix

// before
const body = (await r.json()) as ErrorBody
throw new Error(body.error.message)
// after
let message = `Share failed with status ${r.status}`
try {
  const body = (await r.json()) as ErrorBody
  if (body?.error?.message) message = body.error.message
} catch {}
throw new Error(message)
Defensive patterns

Strategy: try-catch

Validate before calling

if (!navigator.cookieEnabled || !document.cookie) console.warn('No session cookie — share() will likely 401')

Type guard

function isErrorBody(b: unknown): b is ErrorBody {
  return typeof b === 'object' && b !== null && 'error' in b &&
    typeof (b as ErrorBody).error?.message === 'string'
}

Try / catch

try {
  await share(item)
} catch (e) {
  showError(e instanceof Error ? e.message : 'Sharing failed — please log in again')
}

Prevention

When it happens

Trigger: Any non-201 response from POST ${API_HOST}/share when sharing a history item (e.g. session expired, server 500, invalid item payload).

Common situations: 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().

Related errors


AI-assisted analysis of wandb/openui@42d7ab4ab6 (2026-09-01). Data as JSON: /api/errors/e6273084f61fc738. Report an issue: GitHub.