Peter-Schorn / SpotifyAPI

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

When a playlist does not have an image, currentUserPlaylists returns a SpotifyDecodingError. #64

Closed MasterCard20 closed 1 month ago

MasterCard20 commented 2 months ago

I have a few playlists that don't have any images because they only have songs stored locally from my phone. This causes the currentUserPlaylists method to return a SpotifyDecodingError.

Printing description of error:
▿ Optional<Error>
  ▿ some : SpotifyDecodingError: The data from the Spotify web API could not be decoded into 'PagingObject<Playlist<PlaylistItemsReference>>'
URL: https://api.spotify.com/v1/me/playlists?offset=0
http status code: 200
pretty coding path: PagingObject<Playlist<PlaylistItemsReference>>.items[21].images
Underlying error:
▿ Swift.DecodingError.valueNotFound
  ▿ valueNotFound: (2 elements)
    - .0: Swift.Array<Any> #0
    ▿ .1: Swift.DecodingError.Context
      ▿ codingPath: 3 elements
        - CodingKeys(stringValue: "items", intValue: nil)
        ▿ _JSONKey(stringValue: "Index 21", intValue: 21)
          ▿ rep: Foundation._JSONKey.Rep.index
            - index: 21
        - CodingKeys(stringValue: "images", intValue: nil)
      - debugDescription: "Cannot get unkeyed decoding container -- found null value instead"
      - underlyingError: nil

example of the playlist that caused the error:

{
    "collaborative": false,
    "description": "",
    "external_urls": {
        "spotify": "https://open.spotify.com/playlist/6gWDV67cAzoXDpIow4oaEL"
    },
    "href": "https://api.spotify.com/v1/playlists/6gWDV67cAzoXDpIow4oaEL",
    "id": "6gWDV67cAzoXDpIow4oaEL",
    "images": null,
    "name": "Cole - Local",
    "owner": {
        "display_name": "TrebleMakerMusic",
        "external_urls": {
            "spotify": "https://open.spotify.com/user/et4zqfrh33rw2yj22rpn3p71g"
        },
        "href": "https://api.spotify.com/v1/users/et4zqfrh33rw2yj22rpn3p71g",
        "id": "et4zqfrh33rw2yj22rpn3p71g",
        "type": "user",
        "uri": "spotify:user:et4zqfrh33rw2yj22rpn3p71g"
    },
    "primary_color": null,
    "public": true,
    "snapshot_id": "AAAABZvdj+OeMY8mrVShnUa5ksYuYVyH",
    "tracks": {
        "href": "https://api.spotify.com/v1/playlists/6gWDV67cAzoXDpIow4oaEL/tracks",
        "total": 71
    },
    "type": "playlist",
    "uri": "spotify:playlist:6gWDV67cAzoXDpIow4oaEL"
}
Peter-Schorn commented 2 months ago

This should be fixed as of 0379910. See also #57 and #59.