Skip to content

Commit 110b200

Browse files
committed
chore: cleanup MockTransport, moving proper json handling to SentryRequest
1 parent 4dc5a0e commit 110b200

File tree

2 files changed

+4
-30
lines changed

2 files changed

+4
-30
lines changed

dart/lib/src/protocol/sentry_request.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ class SentryRequest {
8989
queryString: json['query_string'],
9090
cookies: json['cookies'],
9191
data: json['data'],
92-
headers: json['headers'],
93-
env: json['env'],
92+
headers: json.containsKey('headers') ? Map.from(json['headers']) : null,
93+
env: json.containsKey('env') ? Map.from(json['env']) : null,
9494
// ignore: deprecated_member_use_from_same_package
95-
other: json['other'],
95+
other: json.containsKey('other') ? Map.from(json['other']) : null,
9696
fragment: json['fragment'],
9797
);
9898
}

dart/test/mocks/mock_transport.dart

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,33 +43,7 @@ class MockTransport implements Transport {
4343

4444
final envelopeItem = utf8.decode(envelopeItemData);
4545
final envelopeItemJson = jsonDecode(envelopeItem.split('\n').last);
46-
final envelopeMap = envelopeItemJson as Map<String, dynamic>;
47-
final requestJson = envelopeMap['request'] as Map<String, dynamic>?;
48-
49-
// TODO the following code should really be part of fromJson() that handle those keys.
50-
// JSON being Map<String, dynamic> is nothing out of ordinary.
51-
// See [SentryResponse.fromJson()] as an example.
52-
53-
// '_InternalLinkedHashMap<dynamic, dynamic>' is not a subtype of type 'Map<String, String>'
54-
final headersMap = requestJson?['headers'] as Map<String, dynamic>?;
55-
final newHeadersMap = <String, String>{};
56-
if (headersMap != null) {
57-
for (final entry in headersMap.entries) {
58-
newHeadersMap[entry.key] = entry.value as String;
59-
}
60-
envelopeMap['request']['headers'] = newHeadersMap;
61-
}
62-
63-
final otherMap = requestJson?['other'] as Map<String, dynamic>?;
64-
final newOtherMap = <String, String>{};
65-
if (otherMap != null) {
66-
for (final entry in otherMap.entries) {
67-
newOtherMap[entry.key] = entry.value as String;
68-
}
69-
envelopeMap['request']['other'] = newOtherMap;
70-
}
71-
72-
return SentryEvent.fromJson(envelopeMap);
46+
return SentryEvent.fromJson(envelopeItemJson);
7347
}
7448

7549
void reset() {

0 commit comments

Comments
 (0)