solid_pod_rs_idp/
error.rs1use thiserror::Error;
4
5use solid_pod_rs::PodError;
6
7#[derive(Debug, Error)]
9pub enum ProviderError {
10 #[error("invalid request: {0}")]
12 InvalidRequest(String),
13
14 #[error("invalid grant: {0}")]
17 InvalidGrant(String),
18
19 #[error("invalid client: {0}")]
21 InvalidClient(String),
22
23 #[error("invalid DPoP: {0}")]
25 InvalidDpop(String),
26
27 #[error("client document: {0}")]
29 ClientDocument(String),
30
31 #[error("password must be at least {min_length} characters")]
34 PasswordTooShort {
35 min_length: usize,
37 },
38
39 #[error("rate limited (retry after {retry_after_secs}s)")]
41 RateLimited {
42 retry_after_secs: u64,
44 },
45
46 #[error("user store: {0}")]
48 UserStore(String),
49
50 #[error("crypto: {0}")]
52 Crypto(String),
53
54 #[error("session: {0}")]
56 Session(String),
57
58 #[error(transparent)]
60 Core(#[from] PodError),
61
62 #[error(transparent)]
64 Io(#[from] std::io::Error),
65
66 #[error("internal: {0}")]
68 Internal(String),
69}
70
71impl ProviderError {
72 pub fn code(&self) -> &'static str {
75 match self {
76 Self::InvalidRequest(_) | Self::PasswordTooShort { .. } => "invalid_request",
77 Self::InvalidGrant(_) => "invalid_grant",
78 Self::InvalidClient(_) => "invalid_client",
79 Self::InvalidDpop(_) => "invalid_dpop_proof",
80 Self::ClientDocument(_) => "invalid_client",
81 Self::RateLimited { .. } => "rate_limited",
82 Self::UserStore(_) | Self::Session(_) | Self::Internal(_) | Self::Io(_) => {
83 "server_error"
84 }
85 Self::Crypto(_) => "server_error",
86 Self::Core(_) => "server_error",
87 }
88 }
89}