Retry S3 GetObject on first-request failures, return 502 for stream errors
This commit is contained in:
@@ -382,8 +382,22 @@ export const videoRoutes = new Elysia({ prefix: "/api/videos" })
|
||||
});
|
||||
}
|
||||
} catch (err: any) {
|
||||
console.error("Stream error:", err);
|
||||
return status(404, { error: "Video not found" });
|
||||
const msg = err?.message || String(err);
|
||||
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",
|
||||
});
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -174,7 +174,24 @@ export async function getVideoStream(
|
||||
...(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) {
|
||||
throw new Error("Empty response body from RustFS");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user