Better exception and docs for missing type info, fixes #472

This commit is contained in:
Jonas Dellinger 2020-06-29 22:52:15 +02:00
parent 27773caa28
commit bfd9663fde
2 changed files with 20 additions and 1 deletions

View File

@ -37,3 +37,20 @@ foreach (PlaylistTrack<IPlayableItem> item in playlist.Tracks.Items)
```
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))");
```

View File

@ -36,7 +36,9 @@ namespace SpotifyAPI.Web
}
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)`");
}
}