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
|
||||
.uri_for_endpoint(&endpoint, Some(self.websocket_scheme()))?;
|
||||
|
||||
loop {
|
||||
log::debug!("Connecting to websocket: {:?}", uri);
|
||||
|
||||
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) {
|
||||
Ok((socket, response)) => {
|
||||
log::debug!("Websocket connected: {:?}", response.status());
|
||||
Ok(WebsocketEventSocket::new(socket))
|
||||
break Ok(WebsocketEventSocket::new(socket))
|
||||
}
|
||||
Err(e) => match &e {
|
||||
Error::ClientError(ce) => match ce.as_str() {
|
||||
@@ -440,22 +441,23 @@ impl<K: AuthenticationStore + Send + Sync> APIInterface for HTTPAPIClient<K> {
|
||||
self.auth_store.set_token(new_token.to_string()).await;
|
||||
|
||||
// try again on the next attempt.
|
||||
return Err(Error::Unauthorized);
|
||||
continue;
|
||||
} else {
|
||||
log::error!("Websocket unauthorized, no credentials provided");
|
||||
return Err(Error::ClientError(
|
||||
break Err(Error::ClientError(
|
||||
"Unauthorized, no credentials provided".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
_ => Err(e),
|
||||
_ => break Err(e),
|
||||
},
|
||||
|
||||
_ => Err(e),
|
||||
_ => break Err(e),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<K: AuthenticationStore + Send + Sync> HTTPAPIClient<K> {
|
||||
pub fn new(base_url: Uri, auth_store: K) -> HTTPAPIClient<K> {
|
||||
|
||||
Reference in New Issue
Block a user