1mod request;
2mod response;
3
4pub use request::Request;
5pub use response::{HttpResponse, Redirect, RedirectRouteBuilder, Response, ResponseExt};
6
7#[derive(Debug)]
12pub struct ParamError {
13 pub param_name: String,
14}
15
16impl From<ParamError> for HttpResponse {
17 fn from(err: ParamError) -> HttpResponse {
18 HttpResponse::json(serde_json::json!({
19 "error": format!("Missing required parameter: {}", err.param_name)
20 }))
21 .status(400)
22 }
23}
24
25impl From<ParamError> for crate::error::FrameworkError {
26 fn from(err: ParamError) -> crate::error::FrameworkError {
27 crate::error::FrameworkError::ParamError {
28 param_name: err.param_name,
29 }
30 }
31}
32
33impl From<ParamError> for Response {
34 fn from(err: ParamError) -> Response {
35 Err(HttpResponse::from(crate::error::FrameworkError::from(err)))
36 }
37}
38
39pub fn text(body: impl Into<String>) -> Response {
41 Ok(HttpResponse::text(body))
42}
43
44pub fn json(body: serde_json::Value) -> Response {
46 Ok(HttpResponse::json(body))
47}