Skip to content

Commit

Permalink
fix: Don't panic if token is still valid
Browse files Browse the repository at this point in the history
1. `None` from `update_token` should only mean "no update needed", should not be used for errors. We now panic when worker channel is not set
2. Callers should correctly handle `None` result
  • Loading branch information
eprst authored Feb 19, 2024
1 parent d4db350 commit 5e916fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 12 deletions.
9 changes: 4 additions & 5 deletions src/spotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,10 @@ impl Spotify {
spotify.set_volume(volume);

spotify.api.set_worker_channel(spotify.channel.clone());
ASYNC_RUNTIME
.get()
.unwrap()
.block_on(spotify.api.update_token().unwrap())
.ok();
spotify
.api
.update_token()
.map(move |h| ASYNC_RUNTIME.get().unwrap().block_on(h).ok());

spotify.api.set_user(user);

Expand Down
3 changes: 1 addition & 2 deletions src/spotify_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ impl WebApi {
}
}))
} else {
error!("worker channel is not set");
None
panic!("worker channel is not set");
}
}

Expand Down
9 changes: 4 additions & 5 deletions src/ui/search_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,11 +392,10 @@ impl SearchResultsView {
// check if API token refresh is necessary before commencing multiple
// requests to avoid deadlock, as the parallel requests might
// simultaneously try to refresh the token
ASYNC_RUNTIME
.get()
.unwrap()
.block_on(self.spotify.api.update_token().unwrap())
.ok();
self.spotify
.api
.update_token()
.map(move |h| ASYNC_RUNTIME.get().unwrap().block_on(h).ok());

// is the query a Spotify URI?
if let Ok(uritype) = query.parse() {
Expand Down

0 comments on commit 5e916fd

Please sign in to comment.