Peter-Schorn/SpotifyAPI

getFromHref returns 'Unknown NSError The data from Spotify could not be decoded into the expected format.' for some albums

Closed this issue · 6 comments

Some album responses cannot be decoded as 'Album' when using the getFromHref method. Response type is set to Album.self.
Not working: https://api.spotify.com/v1/albums/2zffBP6FVUDZ3dsKodfQi6
Working: https://api.spotify.com/v1/albums/6o2MlLAGbWE61paiQzGZYH

Looks like that the non-working one doesn't have anything returned in the available_markets array.

Please post the full error message. See also Debugging.

The availableMarkets property will be decoded into an empty array if it is null or missing from the JSON payload entirely.

Attached the debug output.
Album 2024-06-04 1-28-50.2480 PM.zip

The JSON data could not be decoded into Album because the values for Album.tracks.items[n].linked_from.id are null:

"linked_from": {
  "external_urls": {
    "spotify": "https://open.spotify.com/track/6QmTnPIet8kjuJI15bNPOA"
  },
  "href": "https://api.spotify.com/v1/tracks/6QmTnPIet8kjuJI15bNPOA",
  // why is the id null if the uri is not???
  "id": null,
  "type": "track",
  "uri": "spotify:track:6QmTnPIet8kjuJI15bNPOA"
}

This JSON object is decoded into TrackLink, and the decoding fails because TrackLink.id cannot be nil.

Is it something that you plan to fix in an upcoming commit or is there a workaround on my end I can apply?

Just pushed 3.0.3 with a fix. Please confirm.

Issue is resolved. Thanks very much!