SpotifyAPI icon indicating copy to clipboard operation
SpotifyAPI copied to clipboard

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

Open lazlox opened this issue 1 year ago • 5 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.

lazlox avatar Jun 03 '24 20:06 lazlox

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.

Peter-Schorn avatar Jun 04 '24 12:06 Peter-Schorn

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

lazlox avatar Jun 04 '24 17:06 lazlox

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.

Peter-Schorn avatar Jun 18 '24 03:06 Peter-Schorn

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

lazlox avatar Jun 29 '24 21:06 lazlox

Just pushed 3.0.3 with a fix. Please confirm.

Peter-Schorn avatar Jun 30 '24 03:06 Peter-Schorn

Issue is resolved. Thanks very much!

lazlox avatar Jul 14 '24 17:07 lazlox