-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Proposal for new auto discovery results #427
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,6 +9,35 @@ use super::WpApiDetails; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
const API_ROOT_LINK_HEADER: &str = "https://api.w.org/"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[uniffi::export] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fn new_api_discovery(site_url: String) -> NewUrlDiscoveryResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
todo!() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[derive(Debug, uniffi::Record)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub struct NewUrlDiscoveryResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub user_input_attempt: NewUrlDiscoveryAttemptResult, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub other_successful_attempts: Vec<NewUrlDiscoveryAttemptResult>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub other_failed_attempts: Vec<NewUrlDiscoveryAttemptResult>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+18
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think WDYT about having something like:
Suggested change
IMHO it's rare that you'd want to iterate through the attempts (failed or otherwise) without explaining to the user what you tried, so having explicit names for what we attempted would make the API more discoverable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We currently don't auto attempt We probably wouldn't want both As I mentioned on Slack, I don't think the error belongs here as we can't make a good guess for which error should be raised. We need the error type to be in individual attempt result instead. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh also, I don't think we are doing a separate attempt for redirects - but they might already work because the request executor handles it for us. I'd need a test case to double check this. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
#[derive(Debug, uniffi::Record)] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub struct NewUrlDiscoveryAttemptResult { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub is_network_error: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub is_successful: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub is_the_site_url_same_as_the_user_input: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub is_failed_to_parse_site_url: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub is_failed_to_parsed_api_root: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub is_failed_to_parsed_api_details: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub has_found_api_root_url: bool, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub input_url: String, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub parsed_site_url: Option<Arc<ParsedUrl>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub api_root_url: Option<Arc<ParsedUrl>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub api_details: Option<Arc<WpApiDetails>>, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
// TODO: Not sure about the type for this | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub errors: u32, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pub fn construct_attempts(input_site_url: String) -> Vec<String> { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
let mut attempts = vec![input_site_url.clone()]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if !input_site_url.starts_with("http") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use rstest::rstest; | ||
use serial_test::parallel; | ||
use std::sync::Arc; | ||
use wp_api::login::{UrlDiscoveryError, WpLoginClient}; | ||
use wp_api_integration_tests::AsyncWpNetworking; | ||
|
||
#[rstest] | ||
#[case("http://optional-https.wpmt.co")] // Fails because it's `http` | ||
#[tokio::test] | ||
#[parallel] | ||
async fn test_login_flow_err_url_discovery_failed(#[case] site_url: &str) { | ||
let client = WpLoginClient::new(Arc::new(AsyncWpNetworking::default())); | ||
let err = client | ||
.api_discovery(site_url.to_string()) | ||
.await | ||
.unwrap_err(); | ||
assert!(matches!(err, UrlDiscoveryError::UrlDiscoveryFailed { .. })); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious if this can (or should) be a
Result<NewUrlDiscoveryAttemptResult, UrlDiscoveryAttemptError>
– that'd avoid theis_successful
property (consuming code needs to branch either on a switch statement or onif is_successful
so I don't think increases the costs)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
uniffi
doesn't let us useResult
s in fields. They can only be used as return types for functions. The likely reason being, the errors get mapped to exceptions in other languages - as they don't all have aResult
type that's similar to Rust.