From c7a7f1e016f952cfaf9fe2e54d300a5259fa3676 Mon Sep 17 00:00:00 2001 From: soshial Date: Thu, 30 Sep 2021 16:43:58 +0400 Subject: Improve OpenCellId logging Add error message received from OpenCellId geolocation provider --- .../org/traccar/geolocation/OpenCellIdGeolocationProvider.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java index cb3094e16..5e9779f2d 100644 --- a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java +++ b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java @@ -48,8 +48,14 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider { callback.onSuccess( json.getJsonNumber("lat").doubleValue(), json.getJsonNumber("lon").doubleValue(), 0); + } else if (json.containsKey("error")) { + String errorMessage = json.getJsonString("error").getString(); + if (json.containsKey("code")) { + errorMessage += " Error code: " + json.getInt("code"); + } + callback.onFailure(new GeolocationException(errorMessage)); } else { - callback.onFailure(new GeolocationException("Coordinates are missing")); + callback.onFailure(new GeolocationException("Coordinates are missing.")); } } -- cgit v1.2.3 From 7bd438a9d86b64bd1339c235c58105408e702de8 Mon Sep 17 00:00:00 2001 From: soshial Date: Mon, 4 Oct 2021 14:52:23 +0200 Subject: reorganise IF clause (OpenCellId) --- .../geolocation/OpenCellIdGeolocationProvider.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java index 5e9779f2d..3b64a9a14 100644 --- a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java +++ b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java @@ -48,14 +48,16 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider { callback.onSuccess( json.getJsonNumber("lat").doubleValue(), json.getJsonNumber("lon").doubleValue(), 0); - } else if (json.containsKey("error")) { - String errorMessage = json.getJsonString("error").getString(); - if (json.containsKey("code")) { - errorMessage += " Error code: " + json.getInt("code"); - } - callback.onFailure(new GeolocationException(errorMessage)); } else { - callback.onFailure(new GeolocationException("Coordinates are missing.")); + if (json.containsKey("error")) { + String errorMessage = json.getJsonString("error").getString(); + if (json.containsKey("code")) { + errorMessage += " (" + json.getInt("code") + ")"; + } + callback.onFailure(new GeolocationException(errorMessage)); + } else { + callback.onFailure(new GeolocationException("Coordinates are missing")); + } } } -- cgit v1.2.3 From 5118f5e281de16f5b17d147da462b6cfb16e4d4d Mon Sep 17 00:00:00 2001 From: soshial Date: Mon, 4 Oct 2021 18:58:02 +0200 Subject: fix Json decoding error (OpenCellId) --- .../java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java index 3b64a9a14..2535970d3 100644 --- a/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java +++ b/src/main/java/org/traccar/geolocation/OpenCellIdGeolocationProvider.java @@ -50,7 +50,7 @@ public class OpenCellIdGeolocationProvider implements GeolocationProvider { json.getJsonNumber("lon").doubleValue(), 0); } else { if (json.containsKey("error")) { - String errorMessage = json.getJsonString("error").getString(); + String errorMessage = json.getString("error"); if (json.containsKey("code")) { errorMessage += " (" + json.getInt("code") + ")"; } -- cgit v1.2.3