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

Function get_questions

ch_03/src/main.rs:53–71  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51impl Reject for InvalidId {}
52
53async fn get_questions() -> Result<impl Reply, Rejection> {
54 let question = Question::new(
55 QuestionId::from_str("1").expect("No id provided"),
56 "First Question".to_string(),
57 "Content of question".to_string(),
58 Some(vec!("faq".to_string())),
59 );
60
61 match question.id.0.parse::<i32>() {
62 Err(_) => {
63 Err(warp::reject::custom(InvalidId))
64 },
65 Ok(_) => {
66 Ok(warp::reply::json(
67 &question
68 ))
69 }
70 }
71}
72
73async fn return_error(r: Rejection) -> Result<impl Reply, Rejection> {
74 if let Some(error) = r.find::<CorsForbidden>() {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected