Skip to content

【Question】How can I get my origin handler response in middleware #772

Answered by LyunKi
LyunKi asked this question in Q&A
Discussion options

You must be logged in to vote

finally, I struggled with nested futures and had to write like below...
body => bytes => str => struct => body .a little hard for me.

        Box::pin(async move {
            let result = res_future.await;
            let translation_config = TranslationConfig {
                accept_language,
                ..Default::default()
            };
            match result {
                Ok(response) if !response.status().is_success() => {
                    let body = response.into_body();
                    let body = hyper::body::to_bytes(body)
                        .await
                        .ok()
                        .and_then(|bytes| serde_json::from_slice(&bytes).ok())

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@davidpdrsn
Comment options

Answer selected by davidpdrsn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #771 on February 19, 2022 11:53.