diff --git a/pom.xml b/pom.xml
index 7eedf07..2089c46 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,7 +4,7 @@
com.bigboxer23
switchbotapi-java
- 1.1.4
+ 1.1.5
switchbotapi-java
https://github.com/bigboxer23/switchbotapi-java
diff --git a/src/main/java/com/bigboxer23/switch_bot/SwitchBotApi.java b/src/main/java/com/bigboxer23/switch_bot/SwitchBotApi.java
index b9375cc..e6c8235 100644
--- a/src/main/java/com/bigboxer23/switch_bot/SwitchBotApi.java
+++ b/src/main/java/com/bigboxer23/switch_bot/SwitchBotApi.java
@@ -11,6 +11,7 @@
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import lombok.Getter;
+import okhttp3.Response;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -78,17 +79,17 @@ protected RequestBuilderCallback addAuth() {
* @param apiResponse the API response
* @return true if error occurs
*/
- protected boolean checkForError(IApiResponse apiResponse) {
- return Optional.ofNullable(apiResponse)
- .map(response -> {
- if (response.getStatusCode() != 100) {
- logger.error("error code: " + response.getStatusCode() + " : " + response.getMessage());
+ protected boolean checkForError(Response response, Optional apiResponse) {
+ return apiResponse
+ .map(api -> {
+ if (api.getStatusCode() != 100) {
+ logger.error("error code: " + api.getStatusCode() + " : " + api.getMessage());
return false;
}
return true;
})
.orElseGet(() -> {
- logger.error("null api response");
+ logger.error("Error calling switchbot api: " + response.code() + " " + response.message());
return false;
});
}
diff --git a/src/main/java/com/bigboxer23/switch_bot/SwitchBotDeviceApi.java b/src/main/java/com/bigboxer23/switch_bot/SwitchBotDeviceApi.java
index b70b301..790840b 100644
--- a/src/main/java/com/bigboxer23/switch_bot/SwitchBotDeviceApi.java
+++ b/src/main/java/com/bigboxer23/switch_bot/SwitchBotDeviceApi.java
@@ -7,7 +7,6 @@
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Optional;
-
import okhttp3.RequestBody;
import okhttp3.Response;
import org.slf4j.Logger;
@@ -78,7 +77,7 @@ public void sendDeviceControlCommands(String deviceId, DeviceCommand command) th
*/
private T parseResponse(Response response, Class clazz) throws IOException {
Optional apiResponse = OkHttpUtil.getBody(response, clazz);
- if (apiResponse.isEmpty() || !provider.checkForError(apiResponse.get())) {
+ if (!provider.checkForError(response, (Optional) apiResponse)) {
throw new IOException(response.code() + " " + response.message());
}
return apiResponse.get();