MCPcopy Create free account
hub / github.com/Rust-Web-Development/code / get_questions

Function get_questions

ch_04/ch_04-s4.1.2/src/main.rs:81–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

79impl Reject for InvalidId {}
80
81async fn get_questions() -> Result<impl warp::Reply, warp::Rejection> {
82 let question = Question::new(
83 QuestionId::from_str("1").expect("No id provided"),
84 "First Question".to_string(),
85 "Content of question".to_string(),
86 Some(vec!("faq".to_string())),
87 );
88
89 match question.id.0.parse::<i32>() {
90 Err(_) => {
91 Err(warp::reject::custom(InvalidId))
92 },
93 Ok(_) => {
94 Ok(warp::reply::json(
95 &question
96 ))
97 }
98 }
99}
100
101async fn return_error(r: Rejection) -> Result<impl Reply, Rejection> {
102 if let Some(error) = r.find::<CorsForbidden>() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected