twitch_oauth2/tokens/
errors.rs1#[allow(missing_docs)]
5#[derive(thiserror::Error, Debug, displaydoc::Display)]
6#[cfg(feature = "client")]
7#[non_exhaustive]
8pub enum AppAccessTokenError<RE: std::error::Error + Send + Sync + 'static> {
9 Request(#[source] RE),
11 RequestParseError(#[from] crate::RequestParseError),
13}
14
15#[derive(thiserror::Error, Debug, displaydoc::Display)]
17#[non_exhaustive]
18pub enum ValidationError<RE: std::error::Error + Send + Sync + 'static> {
19 NotAuthorized,
21 RequestParseError(#[from] crate::RequestParseError),
23 Request(#[source] RE),
25 InvalidToken(&'static str),
27}
28
29impl ValidationError<std::convert::Infallible> {
30 pub fn into_other<RE: std::error::Error + Send + Sync + 'static>(self) -> ValidationError<RE> {
32 match self {
33 ValidationError::NotAuthorized => ValidationError::NotAuthorized,
34 ValidationError::RequestParseError(e) => ValidationError::RequestParseError(e),
35 ValidationError::InvalidToken(s) => ValidationError::InvalidToken(s),
36 ValidationError::Request(_) => unreachable!(),
37 }
38 }
39}
40
41#[allow(missing_docs)]
43#[derive(thiserror::Error, Debug, displaydoc::Display)]
44#[non_exhaustive]
45#[cfg(feature = "client")]
46pub enum RevokeTokenError<RE: std::error::Error + Send + Sync + 'static> {
47 RequestParseError(#[from] crate::RequestParseError),
49 RequestError(#[source] RE),
51}
52
53#[allow(missing_docs)]
55#[derive(thiserror::Error, Debug, displaydoc::Display)]
56#[non_exhaustive]
57#[cfg(feature = "client")]
58pub enum RefreshTokenError<RE: std::error::Error + Send + Sync + 'static> {
59 RequestError(#[source] RE),
61 RequestParseError(#[from] crate::RequestParseError),
63 NoClientSecretFound,
67 NoRefreshToken,
69 NoExpiration,
71}
72
73#[derive(thiserror::Error, Debug, displaydoc::Display)]
75#[non_exhaustive]
76#[cfg(feature = "client")]
77pub enum UserTokenExchangeError<RE: std::error::Error + Send + Sync + 'static> {
78 RequestError(#[source] RE),
80 RequestParseError(#[from] crate::RequestParseError),
82 StateMismatch,
84 ValidationError(#[from] ValidationError<RE>),
86}
87
88#[derive(thiserror::Error, Debug, displaydoc::Display)]
90#[non_exhaustive]
91#[cfg(feature = "client")]
92pub enum ImplicitUserTokenExchangeError<RE: std::error::Error + Send + Sync + 'static> {
93 TwitchError {
96 error: Option<String>,
98 description: Option<String>,
100 },
101 StateMismatch,
103 ValidationError(#[from] ValidationError<RE>),
105}
106#[derive(thiserror::Error, Debug, displaydoc::Display)]
108#[non_exhaustive]
109#[cfg(feature = "client")]
110pub enum DeviceUserTokenExchangeError<RE: std::error::Error + Send + Sync + 'static> {
111 DeviceExchangeRequestError(#[source] RE),
113 DeviceExchangeParseError(#[source] crate::RequestParseError),
115 TokenRequestError(#[source] RE),
117 TokenParseError(#[source] crate::RequestParseError),
119 ValidationError(#[from] ValidationError<RE>),
121 NoDeviceCode,
123 Expired,
125}
126
127#[cfg(feature = "client")]
128impl<RE: std::error::Error + Send + Sync + 'static> DeviceUserTokenExchangeError<RE> {
129 pub fn is_pending(&self) -> bool {
131 matches!(self, DeviceUserTokenExchangeError::TokenParseError(
132 crate::RequestParseError::TwitchError(crate::id::TwitchTokenErrorResponse {
133 message,
134 ..
135 }),
136 ) if message == "authorization_pending")
137 }
138}