Macro conn_try
Source macro_rules! conn_try {
($expr:expr, $conn:expr $(,)?) => { ... };
}
Expand description
ยงUnwraps an Result::Ok or returns the Conn with a 500 status.
use trillium::{Conn, conn_try};
use trillium_testing::TestServer;
let handler = |mut conn: Conn| async move {
let request_body_string = conn_try!(conn.request_body_string().await, conn);
let u8: u8 = conn_try!(request_body_string.parse(), conn);
conn.ok(format!("received u8 as body: {}", u8))
};
let app = TestServer::new(handler).await;
app.post("/").with_body("not u8").await.assert_status(500);
app.post("/")
.with_body("10")
.await
.assert_ok()
.assert_body("received u8 as body: 10");