fix: Don't panic if token is still valid
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
This commit is contained in:
committed by
GitHub
parent
d4db350000
commit
5e916fd7ec
@@ -83,11 +83,10 @@ impl Spotify {
|
|||||||
spotify.set_volume(volume);
|
spotify.set_volume(volume);
|
||||||
|
|
||||||
spotify.api.set_worker_channel(spotify.channel.clone());
|
spotify.api.set_worker_channel(spotify.channel.clone());
|
||||||
ASYNC_RUNTIME
|
spotify
|
||||||
.get()
|
.api
|
||||||
.unwrap()
|
.update_token()
|
||||||
.block_on(spotify.api.update_token().unwrap())
|
.map(move |h| ASYNC_RUNTIME.get().unwrap().block_on(h).ok());
|
||||||
.ok();
|
|
||||||
|
|
||||||
spotify.api.set_user(user);
|
spotify.api.set_user(user);
|
||||||
|
|
||||||
|
|||||||
@@ -117,8 +117,7 @@ impl WebApi {
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
error!("worker channel is not set");
|
panic!("worker channel is not set");
|
||||||
None
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -392,11 +392,10 @@ impl SearchResultsView {
|
|||||||
// check if API token refresh is necessary before commencing multiple
|
// check if API token refresh is necessary before commencing multiple
|
||||||
// requests to avoid deadlock, as the parallel requests might
|
// requests to avoid deadlock, as the parallel requests might
|
||||||
// simultaneously try to refresh the token
|
// simultaneously try to refresh the token
|
||||||
ASYNC_RUNTIME
|
self.spotify
|
||||||
.get()
|
.api
|
||||||
.unwrap()
|
.update_token()
|
||||||
.block_on(self.spotify.api.update_token().unwrap())
|
.map(move |h| ASYNC_RUNTIME.get().unwrap().block_on(h).ok());
|
||||||
.ok();
|
|
||||||
|
|
||||||
// is the query a Spotify URI?
|
// is the query a Spotify URI?
|
||||||
if let Ok(uritype) = query.parse() {
|
if let Ok(uritype) = query.parse() {
|
||||||
|
|||||||
Reference in New Issue
Block a user