Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ecovacs] Handle invalid JSON responses properly #16466

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ public EcovacsApiException(String reason) {
this(reason, false);
}

public EcovacsApiException(String reason, Throwable cause) {
super(reason, cause);
isAuthFailure = false;
}

public EcovacsApiException(String reason, boolean isAuthFailure) {
super(reason);
this.isAuthFailure = isAuthFailure;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,18 @@ private <T> T handleResponseWrapper(@Nullable ResponseWrapper<T> response) throw
}

private <T> T handleResponse(ContentResponse response, Class<T> clazz) throws EcovacsApiException {
@Nullable
T respObject = gson.fromJson(response.getContentAsString(), clazz);
if (respObject == null) {
// should not happen in practice
throw new EcovacsApiException("No response received");
try {
@Nullable
T respObject = gson.fromJson(response.getContentAsString(), clazz);
if (respObject == null) {
// should not happen in practice
throw new EcovacsApiException("No response received");
}
return respObject;
} catch (JsonSyntaxException e) {
throw new EcovacsApiException("Failed to parse response '" + response.getContentAsString()
+ "' as data class " + clazz.getSimpleName(), e);
}
return respObject;
}

private Request createAuthRequest(String url, String clientKey, String clientSecret,
Expand Down