Skip to main content

openauth_core/
error.rs

1//! Error types for OpenAuth core.
2
3/// Core library error.
4#[derive(Debug, thiserror::Error, PartialEq, Eq)]
5pub enum OpenAuthError {
6    #[error("invalid configuration: {0}")]
7    InvalidConfig(String),
8    #[error("invalid {encoding} request body: {message}")]
9    InvalidRequestBody {
10        encoding: &'static str,
11        message: String,
12    },
13    #[error("unsupported request content type `{content_type}`")]
14    UnsupportedContentType { content_type: String },
15    #[error("unsupported request content type: missing Content-Type")]
16    MissingContentType,
17    #[error("missing path parameter `{name}`")]
18    MissingPathParam { name: String },
19    #[error("serialization error while {context}: {message}")]
20    Serialization {
21        context: &'static str,
22        message: String,
23    },
24    #[error("{context} lock poisoned")]
25    LockPoisoned { context: &'static str },
26    #[error("{record} record is missing `{field}`")]
27    MissingRecordField { record: &'static str, field: String },
28    #[error("{record} record field `{field}` must be {expected}")]
29    InvalidRecordField {
30        record: &'static str,
31        field: String,
32        expected: &'static str,
33    },
34    #[error("numeric value out of range: {context}")]
35    NumericOutOfRange { context: &'static str },
36    #[error("crypto error: {0}")]
37    Crypto(String),
38    #[error("feature `{feature}` is required for this operation")]
39    FeatureDisabled { feature: &'static str },
40    #[error("invalid secret configuration: {0}")]
41    InvalidSecretConfig(String),
42    #[error("password hash error: {0}")]
43    PasswordHash(String),
44    #[error("cookie error: {0}")]
45    Cookie(String),
46    #[error("api error: {0}")]
47    Api(String),
48    #[error("oauth error: {0}")]
49    OAuth(String),
50    #[error("no request state found in the current async scope")]
51    RequestStateMissing,
52    #[error("request state value had an unexpected type")]
53    RequestStateTypeMismatch,
54    #[error("schema table `{table}` was not found")]
55    TableNotFound { table: String },
56    #[error("schema field `{field}` was not found in table `{table}`")]
57    FieldNotFound { table: String, field: String },
58    #[error(
59        "no foreign key found between base model `{base_model}` and join model `{join_model}`"
60    )]
61    JoinForeignKeyNotFound {
62        base_model: String,
63        join_model: String,
64    },
65    #[error(
66        "multiple foreign keys found between base model `{base_model}` and join model `{join_model}`"
67    )]
68    JoinForeignKeyAmbiguous {
69        base_model: String,
70        join_model: String,
71    },
72    #[error("adapter error: {0}")]
73    Adapter(String),
74}
75
76#[cfg(feature = "oauth")]
77impl From<openauth_oauth::oauth2::OAuthError> for OpenAuthError {
78    fn from(error: openauth_oauth::oauth2::OAuthError) -> Self {
79        Self::OAuth(error.to_string())
80    }
81}