Skip to content

Commit 317abed

Browse files
fix: check HTTP status in FileStream::from_response (#4947) (#4948)
1 parent 4bd49ab commit 317abed

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

packages/fullstack/src/payloads/files.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,24 @@ impl<S> FromRequest<S> for FileStream {
249249
impl FromResponse for FileStream {
250250
fn from_response(res: ClientResponse) -> impl Future<Output = Result<Self, ServerFnError>> {
251251
async move {
252+
// Check status code first - don't try to stream error responses as files
253+
if !res.status().is_success() {
254+
let status_code = res.status().as_u16();
255+
let canonical_reason = res
256+
.status()
257+
.canonical_reason()
258+
.unwrap_or("Unknown error")
259+
.to_string();
260+
let bytes = res.bytes().await.unwrap_or_default();
261+
let message = String::from_utf8(bytes.to_vec()).unwrap_or(canonical_reason);
262+
263+
return Err(ServerFnError::ServerError {
264+
message,
265+
code: status_code,
266+
details: None,
267+
});
268+
}
269+
252270
// Extract filename from Content-Disposition header if present.
253271
let name = res
254272
.headers()

0 commit comments

Comments
 (0)