fix: check HTTP status in FileStream::from_response (#4947) (#4948)

This commit is contained in:
Himmelschmidt authored and GitHub committed 2025-11-11 16:56:36 -03:00
1 parent 4bd49ab989
commit 317abedece
1 file changed
+18
+18
View File
@@ -249,6 +249,24 @@ impl<S> FromRequest<S> for FileStream {
impl FromResponse for FileStream {
fn from_response(res: ClientResponse) -> impl Future<Output = Result<Self, ServerFnError>> {
async move {
// Check status code first - don't try to stream error responses as files
if !res.status().is_success() {
let status_code = res.status().as_u16();
let canonical_reason = res
.status()
.canonical_reason()
.unwrap_or("Unknown error")
.to_string();
let bytes = res.bytes().await.unwrap_or_default();
let message = String::from_utf8(bytes.to_vec()).unwrap_or(canonical_reason);
return Err(ServerFnError::ServerError {
message,
code: status_code,
details: None,
});
}
// Extract filename from Content-Disposition header if present.
let name = res
.headers()