Skip to content

Commit 02c6b1b

Browse files
committed
Merge pull request #111 from mattiamaestrini/fix_spotify_error
Prevent crash when response is malformed
2 parents 3e9bd9c + fdae614 commit 02c6b1b

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyError.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ public class SpotifyError extends Exception {
3737
private final ErrorDetails mErrorDetails;
3838

3939
public static SpotifyError fromRetrofitError(RetrofitError error) {
40-
ErrorResponse errorResponse = (ErrorResponse) error.getBodyAs(ErrorResponse.class);
40+
ErrorResponse errorResponse = null;
41+
42+
try {
43+
errorResponse = (ErrorResponse) error.getBodyAs(ErrorResponse.class);
44+
} catch (Exception e) {
45+
e.printStackTrace();
46+
}
4147

4248
if (errorResponse != null && errorResponse.error != null) {
4349
String message = errorResponse.error.status + " " + errorResponse.error.message;

0 commit comments

Comments
 (0)