File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed
packages/fullstack/src/payloads Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,24 @@ impl<S> FromRequest<S> for FileStream {
249249impl 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 ( )
You can’t perform that action at this time.
0 commit comments