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;