Skip to content

Commit 0304fbb

Browse files
authored
Add catcherror callback for sendData (#72)
* Add catcherror callback for `sendData` * Bump versions
1 parent 6d1dedf commit 0304fbb

File tree

4 files changed

+12
-4
lines changed

4 files changed

+12
-4
lines changed

pkgs/unified_analytics/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.0.1
2+
3+
- Error handling on the `analytics.sendEvent(...)` method to silently error out and return a `500` http status code to let tools using this package know Google Analytics did not receive the event (all successful requests will have a status code of `2xx` provided by Google Analytics)
4+
15
## 1.0.0
26

37
- Error handling functionality added to prevent malformed session json data from causing a crash

pkgs/unified_analytics/lib/src/constants.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ const int kLogFileLength = 2500;
7070
const String kLogFileName = 'dart-flutter-telemetry.log';
7171

7272
/// The current version of the package, should be in line with pubspec version.
73-
const String kPackageVersion = '1.0.0';
73+
const String kPackageVersion = '1.0.1';
7474

7575
/// The minimum length for a session
7676
const int kSessionDurationMinutes = 30;

pkgs/unified_analytics/lib/src/ga_client.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ class GAClient {
4848
/// Receive the payload in Map form and parse
4949
/// into JSON to send to GA
5050
Future<http.Response> sendData(Map<String, Object?> body) {
51-
return _client.post(
51+
return _client
52+
.post(
5253
Uri.parse(postUrl),
5354
headers: <String, String>{
5455
'Content-Type': 'application/json; charset=UTF-8',
5556
},
5657
body: jsonEncode(body),
57-
);
58+
)
59+
.catchError((error) {
60+
return Future<http.Response>.value(http.Response(error.toString(), 500));
61+
});
5862
}
5963
}

pkgs/unified_analytics/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: >-
44
to Google Analytics.
55
# When updating this, keep the version consistent with the changelog and the
66
# value in lib/src/constants.dart.
7-
version: 1.0.0
7+
version: 1.0.1
88
repository: https://github.com/dart-lang/tools/tree/main/pkgs/unified_analytics
99

1010
environment:

0 commit comments

Comments
 (0)