From 328f1764d48babb4e261a1f044c656458351830c Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Sat, 29 Aug 2026 11:08:09 -0500 Subject: [PATCH] archive put: report R2 failures as 503 with the message instead of an uncaught exception --- src/index.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index b124190..a4d6833 100644 --- a/src/index.ts +++ b/src/index.ts @@ -42,10 +42,15 @@ async function putArchive(request: Request, key: string, env: Env): Promise MAX_ARCHIVE_OBJECT_BYTES) return json({ error: "content-length required, ≤ 200 MiB" }, 413); if (request.body === null) return json({ error: "empty body" }, 400); const bucket = bucketFor(key, env); - const object = await bucket.put(key, request.body, { - httpMetadata: { contentType: key.endsWith(".json") ? "application/json" : "application/vnd.apache.parquet" }, - }); - return json({ key, size: object.size, etag: object.httpEtag, bucket: bucket === env.PRIVATE ? "private" : "public" }); + try { + const object = await bucket.put(key, request.body, { + httpMetadata: { contentType: key.endsWith(".json") ? "application/json" : "application/vnd.apache.parquet" }, + }); + return json({ key, size: object.size, etag: object.httpEtag, bucket: bucket === env.PRIVATE ? "private" : "public" }); + } catch (err) { + // an R2 hiccup surfaces here as a 503 with the message, not a bare 1101; the drain retries on 5xx + return json({ error: err instanceof Error ? err.message : "put failed" }, 503); + } } const MAX_BODY_BYTES = 8 << 20; -- 2.51.2