core: HTTPClient: event stream should just automatically retry after auth token
This commit is contained in:
@@ -397,6 +397,7 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
|||||||
let uri = self
|
let uri = self
|
||||||
.uri_for_endpoint(&endpoint, Some(self.websocket_scheme()))?;
|
.uri_for_endpoint(&endpoint, Some(self.websocket_scheme()))?;
|
||||||
|
|
||||||
|
loop {
|
||||||
log::debug!("Connecting to websocket: {:?}", uri);
|
log::debug!("Connecting to websocket: {:?}", uri);
|
||||||
|
|
||||||
let auth = self.auth_store.get_token().await;
|
let auth = self.auth_store.get_token().await;
|
||||||
@@ -428,7 +429,7 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
|||||||
match connect_async(request).await.map_err(Error::from) {
|
match connect_async(request).await.map_err(Error::from) {
|
||||||
Ok((socket, response)) => {
|
Ok((socket, response)) => {
|
||||||
log::debug!("Websocket connected: {:?}", response.status());
|
log::debug!("Websocket connected: {:?}", response.status());
|
||||||
Ok(WebsocketEventSocket::new(socket))
|
break Ok(WebsocketEventSocket::new(socket))
|
||||||
}
|
}
|
||||||
Err(e) => match &e {
|
Err(e) => match &e {
|
||||||
Error::ClientError(ce) => match ce.as_str() {
|
Error::ClientError(ce) => match ce.as_str() {
|
||||||
@@ -440,21 +441,22 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
|||||||
self.auth_store.set_token(new_token.to_string()).await;
|
self.auth_store.set_token(new_token.to_string()).await;
|
||||||
|
|
||||||
// try again on the next attempt.
|
// try again on the next attempt.
|
||||||
return Err(Error::Unauthorized);
|
continue;
|
||||||
} else {
|
} else {
|
||||||
log::error!("Websocket unauthorized, no credentials provided");
|
log::error!("Websocket unauthorized, no credentials provided");
|
||||||
return Err(Error::ClientError(
|
break Err(Error::ClientError(
|
||||||
"Unauthorized, no credentials provided".into(),
|
"Unauthorized, no credentials provided".into(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => Err(e),
|
_ => break Err(e),
|
||||||
},
|
},
|
||||||
|
|
||||||
_ => Err(e),
|
_ => break Err(e),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<K: AuthenticationStore + Send + Sync> HTTPAPIClient<K> {
|
impl<K: AuthenticationStore + Send + Sync> HTTPAPIClient<K> {
|
||||||
|
|||||||
Reference in New Issue
Block a user