mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-23 22:56:25 +00:00
Better exception and docs for missing type info, fixes #472
This commit is contained in:
parent
27773caa28
commit
bfd9663fde
@ -37,3 +37,20 @@ foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)
|
|||||||
```
|
```
|
||||||
|
|
||||||
To this day, `IPlayableItem` can only be `FullTrack` or `FullEpisode`.
|
To this day, `IPlayableItem` can only be `FullTrack` or `FullEpisode`.
|
||||||
|
|
||||||
|
## Fields
|
||||||
|
|
||||||
|
When requesting just a subset of fields using the `fields` query parameter, the call might fail with an exception similar to `Received unkown playlist element type`. For example, the following call fails:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
var playlistGetItemsRequest = new PlaylistGetItemsRequest();
|
||||||
|
playlistGetItemsRequest.Fields.Add("items(track(name))");
|
||||||
|
var playlistItems = await spotify.Playlists.GetItems("YourPlaylistId", playlistGetItemsRequest);
|
||||||
|
```
|
||||||
|
|
||||||
|
By requesting just the track name from the items, we don't have any kind of type information of the item itself. Thus, we're unable to cast it to the correct model. To fix this, include the type in the fields as well:
|
||||||
|
|
||||||
|
```csharp
|
||||||
|
playlistGetItemsRequest.Fields.Add("items(track(name,type))");
|
||||||
|
```
|
||||||
|
|
||||||
|
@ -36,7 +36,9 @@ namespace SpotifyAPI.Web
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new Exception($"Received unkown playlist element type: {type}");
|
throw new Exception($@"Received unkown playlist element type: {type}.
|
||||||
|
If you're requesting a subset of available fields via the fields query paramter,
|
||||||
|
make sure to include at least the type field. Often it's `items(track(type))` or `item(type)`");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user