refactor(user): refresh crate root, error and handler module
zhenyi committed
Modified lib/user/handler/mod.rs lib/user/handler/mod.rs +1 −0 View lib/user/handler/mod.rs
@@ -2,6 +2,7 @@
22pub(crate) mod deletion;
33pub(crate) mod devices;
44pub(crate) mod emails;
5pub(crate) mod middleware;
56pub(crate) mod notifications;
67pub(crate) mod openapi;
78pub(crate) mod preferences;
Modified lib/user/handler/routes.rs lib/user/handler/routes.rs +3 −0 View lib/user/handler/routes.rs
@@ -231,5 +231,8 @@
231231 .merge(me_protected)
232232 .merge(admin_protected)
233233 .layer(from_fn_with_state(svc.clone(), ratelimit::<UserService>))
234 .layer(axum::middleware::from_fn(
235 crate::handler::middleware::metrics::metrics_layer,
236 ))
234237 .with_state(svc)
235238}
No newline at end of file
Modified lib/user/error.rs lib/user/error.rs +18 −0 View lib/user/error.rs
@@ -81,6 +81,24 @@
8181 | UserError::RateLimited(_)
8282 )
8383 }
84
85 /// Low-cardinality label for metrics emission.
86 /// Bounded vocabulary; never derives from the error message body.
87 pub fn error_kind(&self) -> &'static str {
88 match self {
89 UserError::BadRequest(_) => "bad_request",
90 UserError::Unauthorized(_) => "unauthorized",
91 UserError::Forbidden(_) => "forbidden",
92 UserError::NotFound(_) => "not_found",
93 UserError::Conflict(_) => "conflict",
94 UserError::RateLimited(_) => "rate_limited",
95 UserError::Internal(_) => "internal_other",
96 UserError::Sqlx(_) => "internal_db",
97 UserError::Redis(_) => "internal_redis",
98 UserError::Storage(_) => "internal_storage",
99 UserError::Uuid(_) => "internal_uuid",
100 }
101 }
84102}
85103
86104impl IntoResponse for UserError {
Modified lib/user/lib.rs lib/user/lib.rs +1 −0 View lib/user/lib.rs
@@ -2,6 +2,7 @@
22pub mod error;
33pub mod features;
44pub mod handler;
5pub mod metrics;
56
67pub use config::{SharedUserConfig, UserConfig};
78pub use error::{UserError, UserResult};