first attempt: notification code is in dbus::agent
This commit is contained in:
@@ -394,8 +394,7 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
||||
None => "updates".to_string(),
|
||||
};
|
||||
|
||||
let uri = self
|
||||
.uri_for_endpoint(&endpoint, Some(self.websocket_scheme()))?;
|
||||
let uri = self.uri_for_endpoint(&endpoint, Some(self.websocket_scheme()))?;
|
||||
|
||||
loop {
|
||||
log::debug!("Connecting to websocket: {:?}", uri);
|
||||
@@ -426,18 +425,20 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
||||
|
||||
log::debug!("Websocket request: {:?}", request);
|
||||
|
||||
let mut should_retry = true; // retry once after authenticating.
|
||||
let mut should_retry = true; // retry once after authenticating.
|
||||
match connect_async(request).await.map_err(Error::from) {
|
||||
Ok((socket, response)) => {
|
||||
log::debug!("Websocket connected: {:?}", response.status());
|
||||
break Ok(WebsocketEventSocket::new(socket))
|
||||
break Ok(WebsocketEventSocket::new(socket));
|
||||
}
|
||||
Err(e) => match &e {
|
||||
Error::ClientError(ce) => match ce.as_str() {
|
||||
"HTTP error: 401 Unauthorized" | "Unauthorized" => {
|
||||
// Try to authenticate
|
||||
if let Some(credentials) = &self.auth_store.get_credentials().await {
|
||||
log::warn!("Websocket connection failed, attempting to authenticate");
|
||||
log::warn!(
|
||||
"Websocket connection failed, attempting to authenticate"
|
||||
);
|
||||
let new_token = self.authenticate(credentials.clone()).await?;
|
||||
self.auth_store.set_token(new_token.to_string()).await;
|
||||
|
||||
@@ -469,16 +470,16 @@ impl<K: AuthenticationStore + Send + Sync> HTTPAPIClient<K> {
|
||||
let https = HttpsConnector::new();
|
||||
let client = Client::builder().build::<_, Body>(https);
|
||||
|
||||
HTTPAPIClient { base_url, auth_store, client }
|
||||
HTTPAPIClient {
|
||||
base_url,
|
||||
auth_store,
|
||||
client,
|
||||
}
|
||||
}
|
||||
|
||||
fn uri_for_endpoint(&self, endpoint: &str, scheme: Option<&str>) -> Result<Uri, Error> {
|
||||
let mut parts = self.base_url.clone().into_parts();
|
||||
let root_path: PathBuf = parts
|
||||
.path_and_query
|
||||
.ok_or(Error::URLError)?
|
||||
.path()
|
||||
.into();
|
||||
let root_path: PathBuf = parts.path_and_query.ok_or(Error::URLError)?.path().into();
|
||||
|
||||
let path = root_path.join(endpoint);
|
||||
let path_str = path.to_str().ok_or(Error::URLError)?;
|
||||
|
||||
Reference in New Issue
Block a user