yew_oauth2/agent/
error.rs1use crate::context::OAuth2Context;
2use core::fmt::{Display, Formatter};
3
4#[derive(Debug)]
6pub enum OAuth2Error {
7 NotInitialized,
9 Configuration(String),
11 StartLogin(String),
13 LoginResult(String),
15 Refresh(String),
17 Storage(String),
19 Internal(String),
21}
22
23impl Display for OAuth2Error {
24 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
25 match self {
26 Self::NotInitialized => f.write_str("not initialized"),
27 Self::Configuration(err) => write!(f, "configuration error: {err}"),
28 Self::StartLogin(err) => write!(f, "start login error: {err}"),
29 Self::LoginResult(err) => write!(f, "login result: {err}"),
30 Self::Refresh(err) => write!(f, "refresh error: {err}"),
31 Self::Storage(err) => write!(f, "storage error: {err}"),
32 Self::Internal(err) => write!(f, "internal error: {err}"),
33 }
34 }
35}
36
37impl std::error::Error for OAuth2Error {}
38
39impl From<OAuth2Error> for OAuth2Context {
40 fn from(err: OAuth2Error) -> Self {
41 OAuth2Context::Failed(err.to_string())
42 }
43}
44
45impl OAuth2Error {
46 pub(crate) fn storage_key_empty(key: impl Display) -> Self {
47 Self::Storage(format!("Missing value for key: {key}"))
48 }
49}