Macro trillium::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_testing::prelude::*;
use trillium::{Conn, conn_try};

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))
};

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"
);