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