fix: keep screenshot recovery after timeout

This commit is contained in:
ik
2026-09-22 19:57:19 +07:00
parent c46b28d1bc
commit d4ccc93894
3 changed files with 7 additions and 7 deletions
+4 -5
View File
@@ -17,10 +17,9 @@ export const POST: APIRoute = async ({ request, redirect, cookies }) => {
cookies.delete("rf4-idempotency-key", {path:"/"});
}
return redirect(response.ok ? "/report?state=screenshot_sent" : `/report?state=screenshot_error&report_id=${encodeURIComponent(reportId)}`, 303);
} catch (err) {
const isTimeout = err instanceof DOMException && err.name === "TimeoutError" ||
err instanceof TypeError && err.message.toLowerCase().includes("fetch") ||
err instanceof Error && err.message.toLowerCase().includes("abort");
return redirect(isTimeout ? `/report?state=timeout&report_id=${encodeURIComponent(reportId)}` : `/report?state=screenshot_error&report_id=${encodeURIComponent(reportId)}`, 303);
} catch {
// The report already exists and the upload can have reached the API before
// the timeout. Keep the recovery form visible; the API makes a retry safe.
return redirect(`/report?state=screenshot_error&report_id=${encodeURIComponent(reportId)}`, 303);
}
};