WIP #49 Catch http errors inside location isolate
This commit is contained in:
parent
6663bcad72
commit
ab5bf3b807
@ -16,26 +16,22 @@ class LocationManager {
|
|||||||
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
|
Geolocator().getCurrentPosition(desiredAccuracy: LocationAccuracy.medium).then((location) {
|
||||||
Logger.d("[Location isolate #${Isolate.current.hashCode}] Got location: ${location.latitude} ${location.longitude}. Sending home...");
|
Logger.d("[Location isolate #${Isolate.current.hashCode}] Got location: ${location.latitude} ${location.longitude}. Sending home...");
|
||||||
int battery = DateTime.now().hour;
|
int battery = DateTime.now().hour;
|
||||||
try {
|
String url = "$httpWebHost/api/webhook/$webhookId";
|
||||||
String url = "$httpWebHost/api/webhook/$webhookId";
|
Map<String, String> headers = {};
|
||||||
Map<String, String> headers = {};
|
headers["Content-Type"] = "application/json";
|
||||||
headers["Content-Type"] = "application/json";
|
var data = {
|
||||||
var data = {
|
"type": "update_location",
|
||||||
"type": "update_location",
|
"data": {
|
||||||
"data": {
|
"gps": [location.latitude, location.longitude],
|
||||||
"gps": [location.latitude, location.longitude],
|
"gps_accuracy": location.accuracy,
|
||||||
"gps_accuracy": location.accuracy,
|
"battery": battery
|
||||||
"battery": battery
|
}
|
||||||
}
|
};
|
||||||
};
|
http.post(
|
||||||
http.post(
|
url,
|
||||||
url,
|
headers: headers,
|
||||||
headers: headers,
|
body: json.encode(data)
|
||||||
body: json.encode(data)
|
).catchError((e) => print("[Location isolate #${Isolate.current.hashCode}] Error sending data: ${e.toString()}"));
|
||||||
);
|
|
||||||
} catch (e) {
|
|
||||||
print("[Location isolate #${Isolate.current.hashCode}] Error sending location: ${e.toString()}");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -141,7 +137,7 @@ class LocationManager {
|
|||||||
);
|
);
|
||||||
Logger.d("[Location] ...done.");
|
Logger.d("[Location] ...done.");
|
||||||
} else {
|
} else {
|
||||||
print("[Location] No webhook id. Aborting");
|
Logger.d("[Location] No webhook id. Aborting");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Logger.d("[Location] Location tracking is disabled");
|
Logger.d("[Location] Location tracking is disabled");
|
||||||
|
Reference in New Issue
Block a user