{"record":{"id":"235dc97cb697b6c6","repo":"wandb/openui","slug":"unexpected-response-req-status-await-req-tex","errorCode":null,"errorMessage":"Unexpected response ${req.status}: ${await req.text()}","messagePattern":"Unexpected response (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"frontend/src/api/openui.ts","lineNumber":163,"sourceCode":"\t\t\tclient_data_json: asBase64(clientDataJSON),\n\t\t\tsignature: asBase64(signature),\n\t\t\tauthenticator_data: asBase64(authenticatorData)\n\t\t}\n\t}\n\tconst req = await fetch(\n\t\t`${API_HOST}/${create ? 'register' : 'auth'}/${encodeURIComponent(\n\t\t\tusername\n\t\t)}`,\n\t\t{\n\t\t\tcredentials: 'same-origin',\n\t\t\tmethod: 'POST',\n\t\t\tbody: JSON.stringify(data),\n\t\t\theaders: { 'content-type': 'application/json' }\n\t\t}\n\t)\n\n\tif (req.status !== 200) {\n\t\tthrow new Error(`Unexpected response ${req.status}: ${await req.text()}`)\n\t}\n}\n\nexport async function register(username: string): Promise<boolean> {\n\ttry {\n\t\tconst publicKey = (await getPublicKey(\n\t\t\tusername,\n\t\t\ttrue\n\t\t)) as PublicKeyCredentialCreationOptions\n\t\tconsole.log('registration response:', publicKey.user, typeof publicKey.user)\n\t\tpublicKey.user.id = asArrayBuffer(publicKey.user.id as unknown as string)\n\t\tpublicKey.challenge = asArrayBuffer(\n\t\t\tpublicKey.challenge as unknown as string\n\t\t)\n\t\tconst creds = await navigator.credentials.create({ publicKey })\n\t\tawait post(username, creds as PublicKeyCredential, true)\n\t\treturn true\n\t} catch (error) {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/wandb/openui/blob/42d7ab4ab6650433486dfb12eb3783c393a3e475/frontend/src/api/openui.ts#L145-L181","documentation":"post() sends JSON to the backend (used by register and auth for the WebAuthn ceremony result) and expects 200. Any other status throws an Error with the status and raw body text, which the callers' catch blocks then interpret.","triggerScenarios":"Non-200 from POSTing the WebAuthn attestation/assertion: credential rejected or already registered, invalid challenge (expired), or missing session cookie.","commonSituations":"Registering a username that already exists (server returns 4xx whose text contains 'User already exists'); stale WebAuthn challenge after a page reload; browser cancelled the ceremony.","solutions":["Check response text for known strings like 'User already exists' and map them to friendly UI states (register already does this).","Ensure cookies/session persist across getPublicKey and post (credentials: 'same-origin' is required).","Retry the flow from getPublicKey if the challenge expired.","Wrap register/auth in try/catch and show the parsed reason to the user."],"exampleFix":"// before\nthrow new Error(`Unexpected response ${req.status}: ${await req.text()}`)\n// after\nconst text = await req.text()\nthrow new Error(`WebAuthn post failed (${req.status}): ${text.slice(0, 200)}`)","handlingStrategy":"try-catch","validationCode":"if (!credential || !credential.response) throw new Error('WebAuthn ceremony was cancelled or failed')","typeGuard":"function isRegistrationResponse(c: unknown): c is PublicKeyCredential {\n  return typeof c === 'object' && c !== null && 'response' in (c as object)\n}","tryCatchPattern":"try {\n  return await register(username)\n} catch (e) {\n  if (String(e).includes('User already exists')) return false\n  throw e\n}","preventionTips":["Persist the session cookie across the whole ceremony","Restart the flow (fresh options) if the challenge expired","Map known server error strings to friendly UI messages"],"tags":["http","webauthn","typescript","authentication"],"backgroundTag":"webauthn-verification-failed","analyzedSha":"42d7ab4ab6650433486dfb12eb3783c393a3e475","analyzedAt":"2026-09-01T05:00:32.200Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}