mirror of
https://github.com/openhab/openhab-addons.git
synced 2025-01-10 15:11:59 +01:00
[ecovacs] Handle invalid JSON responses properly (#16466)
The API has differing responses depending on device type. If our understanding of the JSON format differs from that of the API, make sure to properly set the thing OFFLINE and to log a meaningful message. Related to #16187 Signed-off-by: Danny Baumann <dannybaumann@web.de>
This commit is contained in:
parent
2edacebf3f
commit
ba0cf3fe1c
@ -27,6 +27,11 @@ public class EcovacsApiException extends Exception {
|
||||
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;
|
||||
|
@ -345,6 +345,7 @@ public final class EcovacsApiImpl implements EcovacsApi {
|
||||
}
|
||||
|
||||
private <T> T handleResponse(ContentResponse response, Class<T> clazz) throws EcovacsApiException {
|
||||
try {
|
||||
@Nullable
|
||||
T respObject = gson.fromJson(response.getContentAsString(), clazz);
|
||||
if (respObject == null) {
|
||||
@ -352,6 +353,10 @@ public final class EcovacsApiImpl implements EcovacsApi {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
private Request createAuthRequest(String url, String clientKey, String clientSecret,
|
||||
|
Loading…
Reference in New Issue
Block a user