Skip to content

Commit fdae614

Browse files
author
Mattia Maestrini
committed
Prevent crash when response is malformed
1 parent 3e9bd9c commit fdae614

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)