coqui_access/error.rs
1//! The refusals providers and hosts agree on, as [`ProviderError`]s.
2//!
3//! The status is what the host acts on; the message is for a person and never contains a
4//! credential.
5
6use guatiao::Status;
7use guatiao::library::ProviderError;
8
9/// The provider does not do this at all. The host does not retry.
10pub fn unsupported(message: &str) -> ProviderError {
11 ProviderError::new(Status::GUATIAO_ERR_UNSUPPORTED, message)
12}
13
14/// The thing asked for does not exist: an account that is not kept.
15pub fn not_found(message: &str) -> ProviderError {
16 ProviderError::new(Status::GUATIAO_ERR_NOT_FOUND, message)
17}
18
19/// The request or the configuration is malformed.
20pub fn bad_value(message: &str) -> ProviderError {
21 ProviderError::new(Status::GUATIAO_ERR_BAD_VALUE, message)
22}
23
24/// Anything else that went wrong inside the provider: storage or a directory was
25/// unreachable. A host treats it as "could not find out", never as "denied".
26pub fn internal(message: &str) -> ProviderError {
27 ProviderError::new(Status::GUATIAO_ERR_INTERNAL, message)
28}
29
30/// What a directory answers when one lookup finds more than one account (a filter that
31/// matches two): a matcher refuses the sign-in rather than choose. A `bad_value` carrying
32/// [`AMBIGUOUS`], so no kind has to change for it.
33pub fn ambiguous() -> ProviderError {
34 ProviderError::new(Status::GUATIAO_ERR_BAD_VALUE, AMBIGUOUS)
35}
36
37/// What a provider answers when it will not take another pending ceremony from a source: a
38/// `bad_value` carrying [`BUSY`], so no kind has to change for it. The caller may try again
39/// later.
40pub fn busy() -> ProviderError {
41 ProviderError::new(Status::GUATIAO_ERR_BAD_VALUE, BUSY)
42}
43
44/// The message of [`busy`].
45pub const BUSY: &str = "BUSY";
46
47/// Whether `error` is [`busy`].
48pub fn is_busy(error: &ProviderError) -> bool {
49 error.status == Status::GUATIAO_ERR_BAD_VALUE && error.message() == BUSY
50}
51
52/// The message of [`ambiguous`].
53pub const AMBIGUOUS: &str = "the lookup finds more than one account";
54
55/// Whether `error` is [`ambiguous`].
56pub fn is_ambiguous(error: &ProviderError) -> bool {
57 error.status == Status::GUATIAO_ERR_BAD_VALUE && error.message() == AMBIGUOUS
58}