Skip to main content

app_forge_kit_http_server/
lib.rs

1#[cfg(feature = "default")]
2mod config;
3#[cfg(feature = "default")]
4mod provider;
5
6#[cfg(feature = "default")]
7pub use config::Config;
8#[cfg(feature = "default")]
9pub use provider::Provider;
10
11#[cfg(feature = "routing")]
12pub mod routing {
13    pub use axum::Router;
14    pub use axum::extract::{FromRef, State};
15    pub use axum::routing::{any, connect, delete, get, head, options, patch, post, put, trace};
16}
17
18pub mod types {
19    pub mod http {
20        pub use http::StatusCode;
21    }
22
23    pub use axum::body::Body;
24    pub use axum::response::{Response, Result};
25}
26
27#[derive(thiserror::Error, Debug)]
28pub enum Error {
29    #[error(transparent)]
30    Unknown(#[from] Box<dyn std::error::Error + Send + Sync>),
31    #[error(transparent)]
32    AddrParseError(#[from] std::net::AddrParseError),
33}
34
35impl axum::response::IntoResponse for Error {
36    fn into_response(self) -> types::Response<types::Body> {
37        let (status_code, message) = match self {
38            Self::Unknown(err) => (http::StatusCode::INTERNAL_SERVER_ERROR, err.to_string()),
39            _ => (
40                http::StatusCode::INTERNAL_SERVER_ERROR,
41                "Unknown error".into(),
42            ),
43        };
44
45        (status_code, message).into_response()
46    }
47}
48
49impl From<Error> for app_forge_kit_service::Error {
50    fn from(err: Error) -> app_forge_kit_service::Error {
51        app_forge_kit_service::Error::Unknown(Box::new(err))
52    }
53}