r_token/models/rtoken_error.rs
1//! ## 日本語
2//!
3//! r-token のエラー型です。
4//!
5//! このライブラリのエラー型は意図的に小さく保っています。主に
6//! [`crate::RTokenManager`] の各メソッドから返されます。また `actix_web::ResponseError`
7//! を実装しているため、actix-web の handler からそのまま返すこともできます。
8//!
9//! ## English
10//!
11//! Error types for r-token.
12//!
13//! The library intentionally keeps its own error type small. It is primarily used
14//! by [`crate::RTokenManager`] methods and can also be returned from HTTP framework handlers
15//! (actix-web / axum) via framework-specific response conversions.
16
17use std::fmt::Formatter;
18
19/// ## 日本語
20///
21/// r-token が返すエラーの一覧です。
22///
23/// ## English
24///
25/// Errors returned by r-token.
26#[derive(Debug)]
27pub enum RTokenError {
28 /// ## 日本語
29 ///
30 /// 内部 mutex が poisoned 状態になりました。
31 ///
32 /// ## English
33 ///
34 /// The internal mutex has been poisoned.
35 MutexPoisoned,
36}
37
38impl std::fmt::Display for RTokenError {
39 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
40 match self {
41 RTokenError::MutexPoisoned => write!(f, "Token manager mutex poisoned"),
42 }
43 }
44}
45
46impl std::error::Error for RTokenError {}
47
48#[cfg(feature = "actix")]
49impl actix_web::ResponseError for RTokenError {}
50
51#[cfg(feature = "axum")]
52impl ::axum::response::IntoResponse for RTokenError {
53 fn into_response(self) -> ::axum::response::Response {
54 (
55 ::axum::http::StatusCode::INTERNAL_SERVER_ERROR,
56 self.to_string(),
57 )
58 .into_response()
59 }
60}