Skip to content

Commit

Permalink
Asynchronous Exceptions
Browse files Browse the repository at this point in the history
~ Proper exceptions in examples
- Try-catch for synchronous auth code uri example
- Try-catch for callables

Closes spotify-web-api-java#128.
  • Loading branch information
dargmuesli committed Feb 10, 2018
1 parent 1c049d5 commit eb142e3
Show file tree
Hide file tree
Showing 75 changed files with 518 additions and 309 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.SpotifyHttpManager;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.credentials.AuthorizationCodeCredentials;
import com.wrapper.spotify.requests.authorization.authorization_code.AuthorizationCodeRequest;

import java.io.IOException;
import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class AuthorizationCodeExample {
Expand All @@ -31,8 +34,8 @@ public static void authorizationCode_Sync() {
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());

System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -49,8 +52,8 @@ public static void authorizationCode_Async() {
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());

System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package authorization.authorization_code;

import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.credentials.AuthorizationCodeCredentials;
import com.wrapper.spotify.requests.authorization.authorization_code.AuthorizationCodeRefreshRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class AuthorizationCodeRefreshExample {
Expand All @@ -28,8 +31,8 @@ public static void authorizationCodeRefresh_Sync() {
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());

System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -46,8 +49,8 @@ public static void authorizationCodeRefresh_Async() {
spotifyApi.setRefreshToken(authorizationCodeCredentials.getRefreshToken());

System.out.println("Expires in: " + authorizationCodeCredentials.getExpiresIn());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.wrapper.spotify.requests.authorization.authorization_code.AuthorizationCodeUriRequest;

import java.net.URI;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class AuthorizationCodeUriExample {
Expand All @@ -24,13 +25,9 @@ public class AuthorizationCodeUriExample {
.build();

public static void authorizationCodeUri_Sync() {
try {
final URI uri = authorizationCodeUriRequest.execute();
final URI uri = authorizationCodeUriRequest.execute();

System.out.println("URI: " + uri.toString());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
}
System.out.println("URI: " + uri.toString());
}

public static void authorizationCodeUri_Async() {
Expand All @@ -42,8 +39,8 @@ public static void authorizationCodeUri_Async() {
final URI uri = uriFuture.get();

System.out.println("URI: " + uri.toString());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package authorization.client_credentials;

import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.credentials.ClientCredentials;
import com.wrapper.spotify.requests.authorization.client_credentials.ClientCredentialsRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class ClientCredentialsExample {
Expand All @@ -25,8 +28,8 @@ public static void clientCredentials_Sync() {
spotifyApi.setAccessToken(clientCredentials.getAccessToken());

System.out.println("Expires in: " + clientCredentials.getExpiresIn());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -42,8 +45,8 @@ public static void clientCredentials_Async() {
spotifyApi.setAccessToken(clientCredentials.getAccessToken());

System.out.println("Expires in: " + clientCredentials.getExpiresIn());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/albums/GetAlbumExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.neovisionaries.i18n.CountryCode;
import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Album;
import com.wrapper.spotify.requests.data.albums.GetAlbumRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetAlbumExample {
Expand All @@ -23,8 +26,8 @@ public static void getAlbum_Sync() {
final Album album = getAlbumRequest.execute();

System.out.println("Name: " + album.getName());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -37,8 +40,8 @@ public static void getAlbum_Async() {
final Album album = albumFuture.get();

System.out.println("Name: " + album.getName());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/albums/GetAlbumsTracksExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import com.neovisionaries.i18n.CountryCode;
import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Paging;
import com.wrapper.spotify.model_objects.specification.TrackSimplified;
import com.wrapper.spotify.requests.data.albums.GetAlbumsTracksRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetAlbumsTracksExample {
Expand All @@ -26,8 +29,8 @@ public static void getAlbumsTracks_Sync() {
final Paging<TrackSimplified> trackSimplifiedPaging = getAlbumsTracksRequest.execute();

System.out.println("Total: " + trackSimplifiedPaging.getTotal());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -40,8 +43,8 @@ public static void getAlbumsTracks_Async() {
final Paging<TrackSimplified> trackSimplifiedPaging = pagingFuture.get();

System.out.println("Total: " + trackSimplifiedPaging.getTotal());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/albums/GetSeveralAlbumsExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.neovisionaries.i18n.CountryCode;
import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Album;
import com.wrapper.spotify.requests.data.albums.GetSeveralAlbumsRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetSeveralAlbumsExample {
Expand All @@ -23,8 +26,8 @@ public static void getSeveralAlbums_Sync() {
final Album[] albums = getSeveralAlbumsRequest.execute();

System.out.println("Length: " + albums.length);
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -37,8 +40,8 @@ public static void getSeveralAlbums_Async() {
final Album[] albums = albumsFuture.get();

System.out.println("Length: " + albums.length);
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/artists/GetArtistExample.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package data.artists;

import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Artist;
import com.wrapper.spotify.requests.data.artists.GetArtistRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetArtistExample {
Expand All @@ -21,8 +24,8 @@ public static void getArtist_Sync() {
final Artist artist = getArtistRequest.execute();

System.out.println("Name: " + artist.getName());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -35,8 +38,8 @@ public static void getArtist_Async() {
final Artist artist = albumFuture.get();

System.out.println("Name: " + artist.getName());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/artists/GetArtistsAlbumsExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

import com.neovisionaries.i18n.CountryCode;
import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.AlbumSimplified;
import com.wrapper.spotify.model_objects.specification.Paging;
import com.wrapper.spotify.requests.data.artists.GetArtistsAlbumsRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetArtistsAlbumsExample {
Expand All @@ -27,8 +30,8 @@ public static void getArtistsAlbums_Sync() {
final Paging<AlbumSimplified> albumSimplifiedPaging = getArtistsAlbumsRequest.execute();

System.out.println("Total: " + albumSimplifiedPaging.getTotal());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -41,8 +44,8 @@ public static void getArtistsAlbums_Async() {
final Paging<AlbumSimplified> albumSimplifiedPaging = pagingFuture.get();

System.out.println("Total: " + albumSimplifiedPaging.getTotal());
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/artists/GetArtistsRelatedArtistsExample.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package data.artists;

import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Artist;
import com.wrapper.spotify.requests.data.artists.GetArtistsRelatedArtistsRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetArtistsRelatedArtistsExample {
Expand All @@ -22,8 +25,8 @@ public static void getArtistsRelatedArtists_Sync() {
final Artist[] artists = getArtistsRelatedArtistsRequest.execute();

System.out.println("Length: " + artists.length);
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -36,8 +39,8 @@ public static void getArtistsRelatedArtists_Async() {
final Artist[] artists = artistsFuture.get();

System.out.println("Length: " + artists.length);
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
11 changes: 7 additions & 4 deletions examples/data/artists/GetArtistsTopTracksExample.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

import com.neovisionaries.i18n.CountryCode;
import com.wrapper.spotify.SpotifyApi;
import com.wrapper.spotify.exceptions.SpotifyWebApiException;
import com.wrapper.spotify.model_objects.specification.Track;
import com.wrapper.spotify.requests.data.artists.GetArtistsTopTracksRequest;

import java.io.IOException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

public class GetArtistsTopTracksExample {
Expand All @@ -24,8 +27,8 @@ public static void getArtistsTopTracks_Sync() {
final Track[] tracks = getArtistsTopTracksRequest.execute();

System.out.println("Length: " + tracks.length);
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (IOException | SpotifyWebApiException e) {
System.out.println("Error: " + e.getMessage());
}
}

Expand All @@ -38,8 +41,8 @@ public static void getArtistsTopTracks_Async() {
final Track[] tracks = artistsFuture.get();

System.out.println("Length: " + tracks.length);
} catch (Exception e) {
System.out.println("Something went wrong!\n" + e.getMessage());
} catch (InterruptedException | ExecutionException e) {
System.out.println("Error: " + e.getCause().getMessage());
}
}
}
Loading

0 comments on commit eb142e3

Please sign in to comment.