Peter-Schorn / SpotifyAPI

A Swift library for the Spotify web API. Supports all endpoints.
https://peter-schorn.github.io/SpotifyAPI/documentation/spotifywebapi
MIT License
265 stars 32 forks source link

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

Closed lazlox closed 2 months ago

lazlox commented 4 months ago

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.

Peter-Schorn commented 4 months ago

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.

lazlox commented 4 months ago

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

Peter-Schorn commented 3 months ago

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.

lazlox commented 3 months ago

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

Peter-Schorn commented 3 months ago

Just pushed 3.0.3 with a fix. Please confirm.

lazlox commented 2 months ago

Issue is resolved. Thanks very much!