diff --git a/src/tasks/oauth.rs b/src/tasks/oauth.rs index b9e5d45..3f7963f 100644 --- a/src/tasks/oauth.rs +++ b/src/tasks/oauth.rs @@ -100,16 +100,25 @@ impl Authenticator { } /// Spawns a task that periodically fetches a new token every 300 seconds. - pub async fn spawn(self) -> JoinHandle<()> { + pub fn spawn(self) -> JoinHandle<()> { let interval = self.config.oauth_token_refresh_interval; - tokio::spawn(async move { + let handle: JoinHandle<()> = tokio::spawn(async move { loop { - tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await; tracing::info!("Refreshing oauth token"); - self.authenticate().await.unwrap(); + match self.authenticate().await { + Ok(_) => { + tracing::info!("Successfully refreshed oauth token"); + } + Err(e) => { + tracing::error!(%e, "Failed to refresh oauth token"); + } + }; + let _sleep = tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await; } - }) + }); + + handle } }