1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
use crate::{AuthExecutionError, AuthorizationFailure, ErrorMessage};
#[derive(Debug, thiserror::Error)]
pub enum WebViewError {
/// Webview Window closed for one of the following reasons:
/// 1. The user closed the webview window without logging in.
/// 2. The webview exited because of a timeout defined in the WebViewOptions.
#[error("window closed: {0:#?}")]
WindowClosed(String),
/// One of the following errors has occurred:
///
/// 1. Issues with the redirect uri such as specifying localhost
/// but not providing a port in the WebViewOptions.
///
/// 2. The webview was successfully redirected but the url did not
/// contain a query or fragment. The query or fragment of the url
/// is where the auth code would be returned to the app.
///
/// 3. The host or domain provided or set for login is invalid.
/// This could be an internal error and most likely will never happen.
#[error("{0:#?}")]
InvalidUri(String),
/// The query or fragment of the redirect uri is an error returned
/// from Microsoft.
#[error("{error:#?}, {error_description:#?}, {error_uri:#?}")]
Authorization {
error: String,
error_description: String,
error_uri: Option<String>,
},
/// Error that happens when building or calling the http request.
#[error("{0:#?}")]
AuthExecutionError(#[from] Box<AuthExecutionError>),
}
impl From<AuthorizationFailure> for WebViewError {
fn from(value: AuthorizationFailure) -> Self {
WebViewError::AuthExecutionError(Box::new(AuthExecutionError::Authorization(value)))
}
}
#[derive(Debug, thiserror::Error)]
pub enum WebViewDeviceCodeError {
/// Webview Window closed for one of the following reasons:
/// 1. The user closed the webview window without logging in.
/// 2. The webview exited because of a timeout defined in the WebViewOptions.
/// 3. The window or event loop was destroyed. The cause is unknown.
#[error("{0:#?}")]
WindowClosed(String),
/// Error that happens calling the http request.
#[error("{0:#?}")]
AuthExecutionError(#[from] Box<AuthExecutionError>),
#[error("{0:#?}")]
DeviceCodePollingError(http::Response<Result<serde_json::Value, ErrorMessage>>),
}
impl From<AuthorizationFailure> for WebViewDeviceCodeError {
fn from(value: AuthorizationFailure) -> Self {
WebViewDeviceCodeError::AuthExecutionError(Box::new(AuthExecutionError::Authorization(
value,
)))
}
}