Skip to content

Commit

Permalink
Added a rawResponse field to the GooglePlayException
Browse files Browse the repository at this point in the history
  • Loading branch information
yeriomin committed Aug 28, 2018
1 parent aa18403 commit 51a1f1d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
public class GooglePlayException extends IOException {

protected int code;
protected byte[] rawResponse;

public GooglePlayException(String message) {
super(message);
Expand All @@ -27,4 +28,12 @@ public void setCode(int code) {
public int getCode() {
return this.code;
}

public byte[] getRawResponse() {
return rawResponse;
}

public void setRawResponse(byte[] rawResponse) {
this.rawResponse = rawResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,19 @@ byte[] request(Request.Builder requestBuilder, Map<String, String> headers) thro
int code = response.code();
byte[] content = response.body().bytes();

if (code == 401 || code == 403) {
AuthException e = new AuthException("Auth error", code);
Map<String, String> authResponse = GooglePlayAPI.parseResponse(new String(content));
if (authResponse.containsKey("Error") && authResponse.get("Error").equals("NeedsBrowser")) {
e.setTwoFactorUrl(authResponse.get("Url"));
if (code >= 400) {
GooglePlayException e = new GooglePlayException("Malformed request", code);
if (code == 401 || code == 403) {
e = new AuthException("Auth error", code);
Map<String, String> authResponse = GooglePlayAPI.parseResponse(new String(content));
if (authResponse.containsKey("Error") && authResponse.get("Error").equals("NeedsBrowser")) {
((AuthException) e).setTwoFactorUrl(authResponse.get("Url"));
}
} else if (code >= 500) {
e = new GooglePlayException("Server error", code);
}
e.setRawResponse(content);
throw e;
} else if (code >= 500) {
throw new GooglePlayException("Server error", code);
} else if (code >= 400) {
throw new GooglePlayException("Malformed request", code);
}

return content;
Expand Down

0 comments on commit 51a1f1d

Please sign in to comment.