Search in sources :

Example 1 with NotFoundException

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);
    }
}
Also used : InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) NotFoundException(se.michaelthelin.spotify.exceptions.detailed.NotFoundException) NoResultsFoundException(net.robinfriedli.aiode.exceptions.NoResultsFoundException) NotFoundException(se.michaelthelin.spotify.exceptions.detailed.NotFoundException) InvalidCommandException(net.robinfriedli.aiode.exceptions.InvalidCommandException) ParseException(org.apache.hc.core5.http.ParseException) SpotifyWebApiException(se.michaelthelin.spotify.exceptions.SpotifyWebApiException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)1 NoResultsFoundException (net.robinfriedli.aiode.exceptions.NoResultsFoundException)1 ParseException (org.apache.hc.core5.http.ParseException)1 SpotifyWebApiException (se.michaelthelin.spotify.exceptions.SpotifyWebApiException)1 NotFoundException (se.michaelthelin.spotify.exceptions.detailed.NotFoundException)1