Skip to content

Commit

Permalink
Readable error on empty or wrong album
Browse files Browse the repository at this point in the history
  • Loading branch information
theirix committed Aug 20, 2023
1 parent e3cb805 commit 0474d53
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lastfmapi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,11 +240,17 @@ impl LastfmApi {
let resp: serde_json::Value = response.json().unwrap();
debug!("Resp {}", resp);

let jtracks = resp
let jalbum = resp
.as_object()
.ok_or(ApiError::Json)?
.get("album")
.ok_or(ApiError::Json)?
.ok_or(ApiError::Json)?;

if jalbum.get("tracks").is_none() {
return Err(ApiError::Unscrobbled("Empty album".into()));
}

let jtracks = jalbum
.get("tracks")
.ok_or(ApiError::Json)?
.get("track")
Expand Down

0 comments on commit 0474d53

Please sign in to comment.