rinukkusu / spotify-dart

A dart library for interfacing with the Spotify API.
BSD 3-Clause "New" or "Revised" License
191 stars 91 forks source link

Catching empty response on `PlaybackState` #192

Closed hayribakici closed 5 months ago

hayribakici commented 6 months ago

Fixes #191. Returns an empty PlaybackState object if the response is empty. @rinukkusu should rather maybe an error be returned instead? E.g.

Future<PlaybackState> playbackState([Market? market]) async {
    var jsonString = await _api._get(...);
    if (jsonString.isEmpty) {
      return Future.error(SpotifyException('No playback context found'));
    }
...
}
rinukkusu commented 5 months ago

Wondering how you would check for a valid PlaybackState. Check if playbackState.item is null? Maybe it's more descriptive to make the return type nullable and just return null as a whole?

I don't think this should be an error, because it's really just "empty" data.

Either way a conflict has to be resolved before I can merge this fix :laughing: