BigPizzaV3/CodexPlusPlus · error
创建分享失败(HTTP )
Error message
创建分享失败(HTTP ${response.status}) What it means
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.
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.
Example fix
// before: no distinction between retryable and non-retryable failures
result = await response.json().catch(() => ({}));
if (!response.ok || !result.id) throw new Error(result.error || `创建分享失败(HTTP ${response.status})`);
// after: branch on status class
result = await response.json().catch(() => ({}));
if (!response.ok || !result.id) {
if (response.status >= 500) {
// retry with backoff before giving up
return retryShareCreation(payload);
}
throw new Error(result.error || `创建分享失败(HTTP ${response.status})`);
} Defensive patterns
Strategy: retry
Validate before calling
if (JSON.stringify(payload).length > MAX_SHARE_BODY_BYTES) throw new Error("分享内容超出服务端大小限制");
if (!(payload.ttl > 0)) throw new Error("TTL 无效"); Type guard
function isShareCreated(v) {
return v != null && typeof v === "object" && typeof v.id === "string" && v.id.length > 0;
} Try / catch
try {
const response = await fetch(`${baseUrl}/api/shares`, { method: "POST", headers, body: JSON.stringify(payload) });
const result = await response.json().catch(() => ({}));
if (!response.ok || !isShareCreated(result)) {
if (response.status >= 500 || response.status === 429) return retryWithBackoff();
throw new Error(result.error || `创建分享失败(HTTP ${response.status})`);
}
} catch (e) {
console.error("直连创建分享失败:", e);
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
AI-assisted analysis of BigPizzaV3/CodexPlusPlus@b1ed92e5e4 (2026-09-19).
Data as JSON: /api/errors/3de939677bc888ee.
Report an issue: GitHub.
Appendix: source
Thrown at assets/inject/renderer-inject.js:7611
result = await postJson("/share/create", payload);
if (result?.id) {
baseUrl = codexPlusShareBaseUrl;
} else if (result?.status !== "failed") {
throw new Error(result?.message || "创建分享失败");
}
} catch (_) {
result = null;
}
if (!result?.id) {
let response;
try {
response = await fetch(`${baseUrl}/api/shares`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) });
} catch (_) {
baseUrl = codexPlusShareFallbackBaseUrl;
response = await fetch(`${baseUrl}/api/shares`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(payload) });
}
result = await response.json().catch(() => ({}));
if (!response.ok || !result.id) throw new Error(result.error || `创建分享失败(HTTP ${response.status})`);
}
const shareUrl = `${baseUrl}/?s=${encodeURIComponent(result.id)}#k=${encrypted.key}`;
try {
await navigator.clipboard.writeText(shareUrl);
} catch (_) {
const input = document.createElement("input");
input.value = shareUrl;
input.style.position = "fixed";
input.style.opacity = "0";
document.body.appendChild(input);
input.select();
document.execCommand("copy");
input.remove();
}
showToast("会话分享链接已复制", null);
if (shareWindow && !shareWindow.closed) shareWindow.location.href = shareUrl;
} catch (error) {
if (shareWindow && !shareWindow.closed) shareWindow.close();View on GitHub (pinned to b1ed92e5e4)