use of se.michaelthelin.spotify.exceptions.detailed.NotFoundException in project aiode by robinfriedli.
the class PlayableFactory method createPlayableForSpotifyUrlType.
private List<Playable> createPlayableForSpotifyUrlType(StringList pathFragments, String type, CheckedFunction<String, List<Playable>> loadFunc, SpotifyApi spotifyApi) {
String id = pathFragments.tryGet(pathFragments.indexOf(type) + 1);
if (Strings.isNullOrEmpty(id)) {
throw new InvalidCommandException(String.format("No %s id provided", type));
}
try {
String accessToken = spotifyApi.clientCredentials().build().execute().getAccessToken();
spotifyApi.setAccessToken(accessToken);
return loadFunc.doApply(id);
} catch (NotFoundException e) {
throw new NoResultsFoundException(String.format("No Spotify track found for id '%s'", id));
} catch (Exception e) {
throw new RuntimeException("Exception during Spotify request", e);
} finally {
spotifyApi.setAccessToken(null);
}
}
Aggregations