Unverified Commit 22f222d9 authored by david-perez's avatar david-perez Committed by GitHub
Browse files

`rust-server-codegen`: don't return 200 status code with rejections (#1000)



Rejections themselves implement `IntoResponse` and set their status
code on it.

Co-authored-by: default avatarMatteo Bigoi <1781140+crisidev@users.noreply.github.com>
parent e559e4cf
Loading
Loading
Loading
Loading
+3 −7
Original line number Diff line number Diff line
@@ -197,9 +197,7 @@ private class ServerHttpProtocolImplGenerator(
                        match #{serialize_response}(&o) {
                            Ok(response) => response,
                            Err(e) => {
                                let mut response = #{http}::Response::builder().body(#{SmithyHttpServer}::body::to_boxed(e.to_string())).expect("unable to build response from output");
                                response.extensions_mut().insert(#{SmithyHttpServer}::ExtensionRejection::new(e.to_string()));
                                response
                                e.into_response()
                            }
                        }
                    },
@@ -210,9 +208,7 @@ private class ServerHttpProtocolImplGenerator(
                                response
                            },
                            Err(e) => {
                                let mut response = #{http}::Response::builder().body(#{SmithyHttpServer}::body::to_boxed(e.to_string())).expect("unable to build response from error");
                                response.extensions_mut().insert(#{SmithyHttpServer}::ExtensionRejection::new(e.to_string()));
                                response
                                e.into_response()
                            }
                        }
                    }
@@ -247,7 +243,7 @@ private class ServerHttpProtocolImplGenerator(
                """
                match #{serialize_response}(&self.0) {
                    Ok(response) => response,
                    Err(e) => #{http}::Response::builder().body(#{SmithyHttpServer}::body::to_boxed(e.to_string())).expect("unable to build response from output")
                    Err(e) => e.into_response()
                }
                """.trimIndent()
            }
+3 −2
Original line number Diff line number Diff line
@@ -46,12 +46,13 @@ macro_rules! define_rejection {
        #[derive(Debug)]
        pub struct $name;

        #[allow(deprecated)]
        impl axum_core::response::IntoResponse for $name {

            fn into_response(self) -> axum_core::response::Response {
                let mut res = http::Response::new(axum_core::body::boxed(http_body::Full::from($body)));
                *res.status_mut() = http::StatusCode::$status;
                res.extensions_mut().insert(
                    crate::ExtensionRejection::new(self.to_string())
                );
                res
            }
        }