fix(api): gracefully handle aborted requests

When a client closes a connection early (e.g. while `await request.text()` is parsing), it throws a `DOMException` with `name: "AbortError"`. Previously, this hit our catch block, was logged as an unhandled exception to the console via `console.error`, and returned a `500` status. This resulted in an alarming error message which looked like a server crash, but the server actually stayed up.

This commit updates `errorResponse` in `src/api.ts` to intercept `AbortError` and handle it properly. If we detect an `AbortError`, we now log a simple `499 Client Closed Request` instead, without writing out the `DOMException` stack trace.
This commit is contained in:
ruinivist
2026-05-31 11:16:01 +00:00
parent 90c2134bbe
commit 7e02863022
+1 -1
View File
@@ -15,7 +15,7 @@ function errorResponse(error: unknown): Response {
}
if (error instanceof Error && error.name === "AbortError") {
return json({ ok: false, error: "Request aborted" }, { status: 400 });
return json({ ok: false, error: "Request aborted" }, { status: 499 });
}
console.error(error);