summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAldrik Ramaekers <aldrik@amftech.nl>2023-07-30 18:57:57 +0200
committerAldrik Ramaekers <aldrik@amftech.nl>2023-07-30 18:57:57 +0200
commitde965e5e165aa53d4900f8b616fba103fbe37844 (patch)
treeac33c3ecf54dac9611d3949f96569faf245094d1 /lib
parentec90a713d4546c645e3288f63ed3d09efd111487 (diff)
log exceptions
Diffstat (limited to 'lib')
-rw-r--r--lib/config/defaults.dart2
-rw-r--r--lib/services/storegear_api_service.dart73
2 files changed, 42 insertions, 33 deletions
diff --git a/lib/config/defaults.dart b/lib/config/defaults.dart
index 507fba8..f0a5919 100644
--- a/lib/config/defaults.dart
+++ b/lib/config/defaults.dart
@@ -1,4 +1,4 @@
-String program_version = '1.1 [10/06/2023]';
+String program_version = '1.2 [30/07/2023]';
bool debug_mode = false;
class ShiftType {
diff --git a/lib/services/storegear_api_service.dart b/lib/services/storegear_api_service.dart
index 0c2cbbc..a37e1d7 100644
--- a/lib/services/storegear_api_service.dart
+++ b/lib/services/storegear_api_service.dart
@@ -27,18 +27,21 @@ class StoregearApiService extends IStoregearApiService {
headers: {'X-REQ-UUID': Uuid().v1()},
body: jsonEncode(req));
- if (response.statusCode == 200) {
- // If the server did return a 200 OK response,
- // then parse the JSON.
- LoginResponse res = LoginResponse.fromJson(jsonDecode(response.body));
- apiKey = res.apiKey!;
- return res;
- } else {
- print(response.body);
+ try {
+ if (response.statusCode == 200) {
+ // If the server did return a 200 OK response,
+ // then parse the JSON.
+
+ LoginResponse res = LoginResponse.fromJson(jsonDecode(response.body));
+ apiKey = res.apiKey!;
+ return res;
+ } else {
+ throw Exception('Failed login');
+ }
+ }
+ catch (ex) {
backupService.writeStringToFile(response.body, 'failed_login.txt');
- // If the server did not return a 200 OK response,
- // then throw an exception.
- throw Exception('Failed login');
+ throw Exception('Failed to load route');
}
}
@@ -58,20 +61,23 @@ class StoregearApiService extends IStoregearApiService {
Uri.parse('http://dhlapis.com/delivery/v1/routes'),
headers: {'X-API-KEY': apiKey, 'X-REQ-UUID': Uuid().v1()});
- if (response.statusCode == 200) {
- // If the server did return a 200 OK response,
- // then parse the JSON.
+ try {
+ if (response.statusCode == 200) {
+ // If the server did return a 200 OK response,
+ // then parse the JSON.
- var content = jsonDecode(response.body);
- if (content["message"] != null) {
- return RouteList(routes: []);
+ var content = jsonDecode(response.body);
+ if (content["message"] != null) {
+ return RouteList(routes: []);
+ }
+ return RouteList.fromJson(content);
+ } else {
+ throw Exception('Failed to load routes');
}
- return RouteList.fromJson(content);
- } else {
+ }
+ catch (ex) {
backupService.writeStringToFile(response.body, 'failed_routelist.txt');
- // If the server did not return a 200 OK response,
- // then throw an exception.
- throw Exception('Failed to load routes');
+ throw Exception('Failed to load route');
}
}
@@ -86,19 +92,22 @@ class StoregearApiService extends IStoregearApiService {
'http://dhlapis.com/delivery/v1/routes/' + tripkey.toString()),
headers: {'X-API-KEY': apiKey, 'X-REQ-UUID': Uuid().v1()});
- if (response.statusCode == 200) {
- // If the server did return a 200 OK response,
- // then parse the JSON.
+ try {
+ if (response.statusCode == 200) {
+ // If the server did return a 200 OK response,
+ // then parse the JSON.
- var content = jsonDecode(response.body);
- if (content["message"] != null) {
- return null;
+ var content = jsonDecode(response.body);
+ if (content["message"] != null) {
+ return null;
+ }
+ return RouteInfo.fromJson(content).route;
+ } else {
+ throw Exception('Failed to load route');
}
- return RouteInfo.fromJson(content).route;
- } else {
+ }
+ catch (ex) {
backupService.writeStringToFile(response.body, 'failed_route.txt');
- // If the server did not return a 200 OK response,
- // then throw an exception.
throw Exception('Failed to load route');
}
}