Macro trillium::conn_try [−][src]
macro_rules! conn_try { ($conn:expr, $expr:expr) => { ... }; }
Expand description
Unwraps an Result::Ok or returns the conn with a 500 status.
use trillium_testing::prelude::*; use trillium::{Conn, conn_try}; let handler = |mut conn: Conn| async move { let request_body_string = conn_try!(conn, conn.request_body_string().await); let u8: u8 = conn_try!(conn, request_body_string.parse()); conn.ok(format!("received u8 as body: {}", u8)) }; assert_status!( post("/").with_request_body("not u8").on(&handler), 500 ); assert_body!( post("/").with_request_body("10").on(&handler), "received u8 as body: 10" );