Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search not working #22

Closed
mjuszczyk1 opened this issue Oct 4, 2019 · 4 comments
Closed

Search not working #22

mjuszczyk1 opened this issue Oct 4, 2019 · 4 comments

Comments

@mjuszczyk1
Copy link

I have spotify_io imported like

import 'package:spotify/spotify_io.dart';

Copied the search from the examples directory on this repo

var credentials =
    new SpotifyApiCredentials(spotifyClientId, spotifyClientSecret);
var spotify = new SpotifyApi(credentials);
var search = await spotify.search
    .get("metallica")
    .first(2)
    .catchError((err) => print((err as SpotifyException).message));

And I get a couple errors, the first one seems like a pretty simple fix:

  1. [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '_TypeError' is not a subtype of type 'SpotifyException' in type cast - this error can be fixed by removing the as SpotifyException cast. I first solved the issue by simply removing the catchError method, which revealed the second bug.
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic>'
E/flutter ( 5063): #0      SpotifyApi.handleErrors      package:spotify/src/spotify_io.dart:37
E/flutter ( 5063): #1      SpotifyApi._postImpl         package:spotify/src/spotify_io.dart:21

I dug into this one a bit, but I'm pretty new to Dart/Flutter in general so I couldn't figure out a fix. I believe I traced it, at least, to a line in endpoint_paging.dart - specifically line 163. It seems the _get method is where this bug is actually being generated - I can get a breakpoint to hit on var jsonString = await _api._get(path);, but if I remove it and add one to the next line (var map = json.decode(jsonString);), it never gets hit. I also can't get breakpoints to work in that _get method, so I think this is pretty close to where the bug is coming from, but I'm currently stuck scratching my head.

@mjuszczyk1
Copy link
Author

Figured this out a while ago, forgot to update this.

This can probably be closed, as it's not necessarily a problem with search, per se - the problem was, due to some lazy copy/pasting, I was using spotifyClientId for spotifyClientSecret so I was getting a 401 error.
The part that could be improved is actually throwing that as an error because it does not appear in a debug console (personally just using VisualStudio Code for running/debugging).

hayribakici added a commit to hayribakici/spotify-dart that referenced this issue Feb 11, 2020
- propagates `SpotifyException` when dealing with `BundledPage` response
- allows error provocation when using unti test
hayribakici added a commit to hayribakici/spotify-dart that referenced this issue Feb 11, 2020
- adds more test asserts
rinukkusu added a commit that referenced this issue Feb 11, 2020
@rinukkusu
Copy link
Owner

I'll release a new package tomorrow, when I'm back on a real computer :)

@hayribakici
Copy link
Collaborator

hayribakici commented Feb 17, 2020

@mjuszczyk1 does the #29 PR solve this issue? @rinukkusu Can this be closed?

@rinukkusu
Copy link
Owner

v0.2.1 with said changes has just been released.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants