From 45442af41d50b74d51304e7736b7b15fd35364dd Mon Sep 17 00:00:00 2001 From: John Costa Date: Mon, 30 Mar 2026 18:46:48 -0700 Subject: [PATCH] fix(server): don't redirect error responses from #[get] server functions (#5429) The post-handler redirect logic was unconditionally converting responses to 302 Found when the request had Accept: text/html and a Referer header. This overwrote error status codes (4xx, 5xx), making it impossible to return errors from #[get] endpoints accessed via browser navigation. Add a response.status().is_success() guard so only successful responses get the Post/Redirect/Get treatment. Fixes #5428 --- packages/fullstack-server/src/serverfn.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/fullstack-server/src/serverfn.rs b/packages/fullstack-server/src/serverfn.rs index 2c6ee689f..744dad44f 100644 --- a/packages/fullstack-server/src/serverfn.rs +++ b/packages/fullstack-server/src/serverfn.rs @@ -113,9 +113,11 @@ impl ServerFunction { response.headers_mut().extend(headers); } - // if it accepts text/html (i.e., is a plain form post) and doesn't already have a - // Location set, then redirect to Referer - if accepts_html { + // If the response is successful and accepts text/html (i.e., is a + // plain form post) and doesn't already have a Location set, then + // redirect to Referer. Only redirect on success so that error + // responses (4xx, 5xx) propagate correctly to the client. + if accepts_html && response.status().is_success() { if let Some(referrer) = referrer { let has_location = response.headers().get(LOCATION).is_some(); if !has_location {