Skip to content

Commit

Permalink
Improved error handling and recovery
Browse files Browse the repository at this point in the history
  • Loading branch information
compenguy committed Apr 7, 2020
1 parent 9315ae0 commit 6ef17ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/caching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ fn tag_mp3<P: AsRef<Path>>(track: &PlaylistTrack, path: P) -> Result<()> {

fn save_url_to_file<P: AsRef<Path>>(url: &str, path: P) -> Result<()> {
let mut resp = reqwest::blocking::get(url)
.with_context(|| format!("Failed while retrieving content from url {}", url))?;
.with_context(|| format!("Failed while retrieving content from url {}", url))?
.error_for_status()
.with_context(|| format!("Error response while retrieving content from url {}", url))?;

let file = std::fs::File::create(path.as_ref()).with_context(|| {
format!(
Expand Down
8 changes: 8 additions & 0 deletions src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,13 @@ impl PlaybackMediator for Playing {
Some(serde_json::value::Value::String(cached)) => PathBuf::from(cached.clone()),
_ => match caching::add_to_cache(track) {
Err(e) => {
if let Some(e) = e.downcast_ref::<reqwest::Error>() {
if e.is_status() {
error!("Failed caching track due to http error: {:?}", e);
self.evict_playing();
return;
}
}
error!("Failed caching track: {:?}", e);
return;
}
Expand Down Expand Up @@ -727,6 +734,7 @@ impl StateMediator for Model {
trace!("start dirtied");
}
} else if self.config.borrow().login_credentials().get().is_some() {
self.disconnect();
self.connect();
if !old_dirty && (old_dirty != self.dirty) {
trace!("connect dirtied");
Expand Down

0 comments on commit 6ef17ee

Please sign in to comment.