fix: restore code queue task submission
- catch async route rejections before Bun fallback HTML\n- return structured JSON for missing reference task ids\n- harden frontend direct proxy JSON handling
This commit is contained in:
@@ -707,6 +707,7 @@ async function proxyCodeQueueDirect(req: Request, url: URL): Promise<Response> {
|
||||
}
|
||||
const overviewCacheKey = `${suffix}${url.search}`;
|
||||
const canUseOverviewCache = req.method === "GET" && suffix === "/api/tasks/overview";
|
||||
const expectsJsonResponse = suffix === "/health" || suffix.startsWith("/api/");
|
||||
if (req.method !== "GET" && req.method !== "HEAD") invalidateCodeQueueOverviewCache();
|
||||
if (canUseOverviewCache) {
|
||||
const cached = cachedCodeQueueOverview(overviewCacheKey);
|
||||
@@ -736,8 +737,28 @@ async function proxyCodeQueueDirect(req: Request, url: URL): Promise<Response> {
|
||||
const isJsonResponse = (upstreamContentType ?? "").toLowerCase().includes("json");
|
||||
let parsedJson: unknown = null;
|
||||
let jsonText = "";
|
||||
if (canUseOverviewCache && upstream.ok && isJsonResponse) {
|
||||
if (expectsJsonResponse) {
|
||||
jsonText = new TextDecoder().decode(upstreamBody);
|
||||
if (!isJsonResponse) {
|
||||
logger("warn", "code_queue_direct_proxy_non_json", {
|
||||
path: suffix,
|
||||
upstreamUrl: upstreamUrl.toString(),
|
||||
status: upstream.status,
|
||||
contentType: upstreamContentType,
|
||||
bodyBytes: upstreamBody.byteLength,
|
||||
preview: safePreview(jsonText),
|
||||
});
|
||||
return jsonResponse({
|
||||
ok: false,
|
||||
error: {
|
||||
message: "code-queue upstream returned non-JSON response",
|
||||
status: upstream.status,
|
||||
contentType: upstreamContentType,
|
||||
bodyBytes: upstreamBody.byteLength,
|
||||
preview: safePreview(jsonText),
|
||||
},
|
||||
}, 502);
|
||||
}
|
||||
try {
|
||||
parsedJson = jsonText ? JSON.parse(jsonText) as unknown : null;
|
||||
} catch (error) {
|
||||
@@ -757,14 +778,15 @@ async function proxyCodeQueueDirect(req: Request, url: URL): Promise<Response> {
|
||||
detail,
|
||||
status: upstream.status,
|
||||
bodyBytes: upstreamBody.byteLength,
|
||||
contentType: upstreamContentType,
|
||||
preview: safePreview(jsonText),
|
||||
},
|
||||
}, 502);
|
||||
}
|
||||
}
|
||||
if (canUseOverviewCache && upstream.ok && isJsonResponse) {
|
||||
if (expectsJsonResponse) {
|
||||
const text = jsonText;
|
||||
if (typeof parsedJson === "object" && parsedJson !== null) {
|
||||
if (canUseOverviewCache && upstream.ok && typeof parsedJson === "object" && parsedJson !== null) {
|
||||
codeQueueOverviewCache.set(codeQueueOverviewCacheKey(overviewCacheKey), { at: Date.now(), payload: parsedJson as JsonValue, text });
|
||||
}
|
||||
return new Response(text, { status: upstream.status, headers: responseHeaders });
|
||||
|
||||
Reference in New Issue
Block a user