Skip to content
Clone

refactor(project): refresh crate root, handler module and error

zhenyi committed
parent 1c7b711 commit ab6748b Browse files

4 files changed

+24 −0

File tree 4
Modified lib/project/handler/mod.rs View lib/project/handler/mod.rs
@@ -4,6 +4,7 @@
44pub(crate) mod lifecycle;
55pub(crate) mod links;
66pub(crate) mod members;
7pub(crate) mod middleware;
78pub(crate) mod views;
89
910pub mod openapi;
Modified lib/project/handler/routes.rs View lib/project/handler/routes.rs
@@ -77,5 +77,8 @@
7777 Router::new()
7878 .merge(protected)
7979 .layer(from_fn_with_state(svc.clone(), ratelimit::<ProjectService>))
80 .layer(axum::middleware::from_fn(
81 crate::handler::middleware::metrics::metrics_layer,
82 ))
8083 .with_state(svc)
8184}
No newline at end of file
Modified lib/project/error.rs View lib/project/error.rs
@@ -85,6 +85,25 @@
8585 | ProjectError::RateLimited(_)
8686 )
8787 }
88
89 /// Bounded label for metrics. Keep stable and low-cardinality.
90 pub fn error_kind(&self) -> &'static str {
91 match self {
92 ProjectError::BadRequest(_) => "bad_request",
93 ProjectError::Unauthorized(_) => "unauthorized",
94 ProjectError::Forbidden(_) => "forbidden",
95 ProjectError::NotFound(_) => "not_found",
96 ProjectError::Conflict(_) => "conflict",
97 ProjectError::Unprocessable(_) => "unprocessable",
98 ProjectError::RateLimited(_) => "rate_limited",
99 ProjectError::Internal(_) => "internal_other",
100 ProjectError::Database(_) => "internal_db",
101 ProjectError::Uuid(_) => "internal_uuid",
102 ProjectError::Json(_) => "internal_json",
103 ProjectError::Cache(_) => "internal_cache",
104 ProjectError::Space(_) => "internal_space",
105 }
106 }
88107}
89108
90109impl IntoResponse for ProjectError {
Modified lib/project/lib.rs View lib/project/lib.rs
@@ -5,6 +5,7 @@
55pub mod features;
66pub mod graphql;
77pub mod handler;
8pub mod metrics;
89pub mod permission;
910pub mod service;
1011