{"record":{"id":"3de939677bc888ee","repo":"BigPizzaV3/CodexPlusPlus","slug":"http-response-status","errorCode":null,"errorMessage":"创建分享失败（HTTP ${response.status}）","messagePattern":"创建分享失败（HTTP (.+?)）","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"assets/inject/renderer-inject.js","lineNumber":7611,"sourceCode":"        result = await postJson(\"/share/create\", payload);\n        if (result?.id) {\n          baseUrl = codexPlusShareBaseUrl;\n        } else if (result?.status !== \"failed\") {\n          throw new Error(result?.message || \"创建分享失败\");\n        }\n      } catch (_) {\n        result = null;\n      }\n      if (!result?.id) {\n        let response;\n        try {\n          response = await fetch(`${baseUrl}/api/shares`, { method: \"POST\", headers: { \"Content-Type\": \"application/json\" }, body: JSON.stringify(payload) });\n        } catch (_) {\n          baseUrl = codexPlusShareFallbackBaseUrl;\n          response = await fetch(`${baseUrl}/api/shares`, { method: \"POST\", headers: { \"Content-Type\": \"application/json\" }, body: JSON.stringify(payload) });\n        }\n        result = await response.json().catch(() => ({}));\n        if (!response.ok || !result.id) throw new Error(result.error || `创建分享失败（HTTP ${response.status}）`);\n      }\n      const shareUrl = `${baseUrl}/?s=${encodeURIComponent(result.id)}#k=${encrypted.key}`;\n      try {\n        await navigator.clipboard.writeText(shareUrl);\n      } catch (_) {\n        const input = document.createElement(\"input\");\n        input.value = shareUrl;\n        input.style.position = \"fixed\";\n        input.style.opacity = \"0\";\n        document.body.appendChild(input);\n        input.select();\n        document.execCommand(\"copy\");\n        input.remove();\n      }\n      showToast(\"会话分享链接已复制\", null);\n      if (shareWindow && !shareWindow.closed) shareWindow.location.href = shareUrl;\n    } catch (error) {\n      if (shareWindow && !shareWindow.closed) shareWindow.close();","sourceCodeStart":7593,"sourceCodeEnd":7629,"githubUrl":"https://github.com/BigPizzaV3/CodexPlusPlus/blob/b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6/assets/inject/renderer-inject.js#L7593-L7629","documentation":"Thrown when the direct fallback HTTP call to POST {baseUrl}/api/shares returns a non-2xx status or a body without an id. The template embeds the HTTP status (创建分享失败（HTTP xxx）) unless the response body supplies a more specific error string. This is the last-resort share creation path after the /share/create bridge failed, covering both the primary and fallback share base URLs.","triggerScenarios":"POST /api/shares responds with 4xx/5xx (bad payload, auth failure, rate limit, server error) or 2xx with a body lacking id; fetch succeeds at transport level but the API rejects the share.","commonSituations":"Share service is down or behind an auth wall (401/403); payload exceeds server body limits (413); ttl or encrypted payload rejected (400); the primary base URL is unreachable so the fallback URL is used and also fails; CORS or CDN returning HTML error pages.","solutions":["Read the thrown message for the HTTP status: 4xx indicates a request problem (check payload, auth, ttl), 5xx indicates a server-side problem (retry later).","Verify the encrypted payload size and ttl value meet the share API's limits (payload-too-large and validation errors are common).","Check the share site's availability at baseUrl and codexPlusShareFallbackBaseUrl (e.g. open the health endpoint in a browser).","If 401/403, re-authenticate or check that anonymous share creation is still permitted by the service."],"exampleFix":"// before: no distinction between retryable and non-retryable failures\nresult = await response.json().catch(() => ({}));\nif (!response.ok || !result.id) throw new Error(result.error || `创建分享失败（HTTP ${response.status}）`);\n// after: branch on status class\nresult = await response.json().catch(() => ({}));\nif (!response.ok || !result.id) {\n  if (response.status >= 500) {\n    // retry with backoff before giving up\n    return retryShareCreation(payload);\n  }\n  throw new Error(result.error || `创建分享失败（HTTP ${response.status}）`);\n}","handlingStrategy":"retry","validationCode":"if (JSON.stringify(payload).length > MAX_SHARE_BODY_BYTES) throw new Error(\"分享内容超出服务端大小限制\");\nif (!(payload.ttl > 0)) throw new Error(\"TTL 无效\");","typeGuard":"function isShareCreated(v) {\n  return v != null && typeof v === \"object\" && typeof v.id === \"string\" && v.id.length > 0;\n}","tryCatchPattern":"try {\n  const response = await fetch(`${baseUrl}/api/shares`, { method: \"POST\", headers, body: JSON.stringify(payload) });\n  const result = await response.json().catch(() => ({}));\n  if (!response.ok || !isShareCreated(result)) {\n    if (response.status >= 500 || response.status === 429) return retryWithBackoff();\n    throw new Error(result.error || `创建分享失败（HTTP ${response.status}）`);\n  }\n} catch (e) {\n  console.error(\"直连创建分享失败:\", e);\n  throw e;\n}","preventionTips":["Retry 5xx/429 with exponential backoff before surfacing the error.","Pre-check payload size and ttl client-side to avoid deterministic 4xx failures.","Verify both primary and fallback base URLs during app startup and surface an early warning if unreachable.","Include the response body's error field in user-facing messages for faster diagnosis."],"tags":["http","share","network","api"],"backgroundTag":"http-error-response","analyzedSha":"b1ed92e5e4a2d74095d4b8db5af43cef7acba9c6","analyzedAt":"2026-09-19T23:35:21.129Z","contentChangedAt":"2026-09-19T23:35:21.129Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}