[miio] avoid Invalid URI host: null error (#8867) for 2.5 (#8898)

* [miio] avoid Invalid URI host: null error (#8867)

* [miio] avoid Invalid URI host: null error

Signed-off-by: Marcel Verpaalen <marcel@verpaalen.com>
This commit is contained in:
Marcel 2020-11-05 20:46:52 +01:00 committed by GitHub
parent be0b3cf5b9
commit 06e30201e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -137,14 +137,22 @@ public class CloudConnector {
mapCountry = country.trim().toLowerCase(); mapCountry = country.trim().toLowerCase();
mapUrl = cl.getMapUrl(mapId, mapCountry); mapUrl = cl.getMapUrl(mapId, mapCountry);
} }
@Nullable if (mapUrl.isEmpty()) {
RawType mapData = HttpUtil.downloadData(mapUrl, null, false, -1); logger.debug("Cannot download map data: Returned map URL is empty");
if (mapData != null) {
return mapData;
} else {
logger.debug("Could not download '{}'", mapUrl);
return null; return null;
} }
try {
RawType mapData = HttpUtil.downloadData(mapUrl, null, false, -1);
if (mapData != null) {
return mapData;
} else {
logger.debug("Could not download '{}'", mapUrl);
return null;
}
} catch (IllegalArgumentException e) {
logger.debug("Error downloading map: {}", e.getMessage());
}
return null;
} }
public void setCredentials(@Nullable String username, @Nullable String password, @Nullable String country) { public void setCredentials(@Nullable String username, @Nullable String password, @Nullable String country) {

View File

@ -160,7 +160,8 @@ public class MiCloudConnector {
if (response.getAsJsonObject().has("result") && response.getAsJsonObject().get("result").isJsonObject()) { if (response.getAsJsonObject().has("result") && response.getAsJsonObject().get("result").isJsonObject()) {
JsonObject jo = response.getAsJsonObject().get("result").getAsJsonObject(); JsonObject jo = response.getAsJsonObject().get("result").getAsJsonObject();
if (jo.has("url")) { if (jo.has("url")) {
return jo.get("url").getAsString(); String mapUrl = jo.get("url").getAsString();
return mapUrl != null ? mapUrl : "";
} else { } else {
errorMsg = "Could not get url"; errorMsg = "Could not get url";
} }