Retry S3 GetObject on first-request failures, return 502 for stream errors

This commit is contained in:
CallMeVerity
2026-06-03 06:55:57 +01:00
parent c0b93a2a6e
commit f0f50a6f12
2 changed files with 34 additions and 3 deletions
+16 -2
View File
@@ -382,8 +382,22 @@ export const videoRoutes = new Elysia({ prefix: "/api/videos" })
}); });
} }
} catch (err: any) { } catch (err: any) {
console.error("Stream error:", err); const msg = err?.message || String(err);
return status(404, { error: "Video not found" }); console.error(
"Stream error for video",
id,
"key",
video.transcodedKey ?? video.videoKey,
":",
msg,
);
const statusCode = msg.includes("NoSuchKey") ? 404 : 502;
return status(statusCode, {
error:
statusCode === 404
? "Video not found"
: "Failed to stream video",
});
} }
}) })
+18 -1
View File
@@ -174,7 +174,24 @@ export async function getVideoStream(
...(rangeHeader ? { Range: rangeHeader } : {}), ...(rangeHeader ? { Range: rangeHeader } : {}),
}); });
const result = await s3.send(command); let result;
try {
result = await s3.send(command);
} catch (firstError: any) {
console.warn(
`[stream] First attempt failed for key=${key}:`,
firstError?.message || firstError,
);
try {
result = await s3.send(command);
} catch (secondError: any) {
console.error(
`[stream] Second attempt also failed for key=${key}:`,
secondError?.message || secondError,
);
throw secondError;
}
}
if (!result.Body) { if (!result.Body) {
throw new Error("Empty response body from RustFS"); throw new Error("Empty response body from RustFS");
} }