Skip to content

Commit e985153

Browse files
authored
Merge pull request #56 from Amwam/feature/fix-android
Fix missing keys in Android event context
2 parents 94b0bd7 + d9be263 commit e985153

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

android/src/main/java/io/sentry/RNSentryModule.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -132,14 +132,15 @@ public void captureEvent(ReadableMap event) {
132132
.withLogger(event.getString("logger"))
133133
.withLevel(eventLevel(event.getString("level")));
134134

135-
eventBuilder.withSentryInterface(
136-
new UserInterface(
137-
event.getMap("user").getString("userID"),
138-
event.getMap("user").getString("username"),
139-
null,
140-
event.getMap("user").getString("email")
141-
)
142-
);
135+
if (event.hasKey("user")) {
136+
UserInterface userInterface = new UserInterface(
137+
event.getMap("user").getString("userID"),
138+
event.getMap("user").getString("username"),
139+
null,
140+
event.getMap("user").getString("email")
141+
);
142+
eventBuilder.withSentryInterface(userInterface);
143+
}
143144

144145
helper.helpBuildingEvent(eventBuilder);
145146

@@ -148,18 +149,25 @@ public void captureEvent(ReadableMap event) {
148149
eventBuilder.withExtra(entry.getKey(), entry.getValue());
149150
}
150151
}
151-
for (Map.Entry<String, Object> entry : castEvent.getMap("extra").toHashMap().entrySet()) {
152-
eventBuilder.withExtra(entry.getKey(), entry.getValue());
152+
153+
if (castEvent.hasKey("extra")) {
154+
for (Map.Entry<String, Object> entry : castEvent.getMap("extra").toHashMap().entrySet()) {
155+
eventBuilder.withExtra(entry.getKey(), entry.getValue());
156+
}
153157
}
154158

155159
if (this.tags != null) {
156160
for (Map.Entry<String, Object> entry : ((ReadableNativeMap)this.tags).toHashMap().entrySet()) {
157161
eventBuilder.withExtra(entry.getKey(), entry.getValue());
158162
}
159163
}
160-
for (Map.Entry<String, Object> entry : castEvent.getMap("tags").toHashMap().entrySet()) {
161-
eventBuilder.withTag(entry.getKey(), entry.getValue().toString());
164+
165+
if (castEvent.hasKey("tags")) {
166+
for (Map.Entry<String, Object> entry : castEvent.getMap("tags").toHashMap().entrySet()) {
167+
eventBuilder.withTag(entry.getKey(), entry.getValue().toString());
168+
}
162169
}
170+
163171
Event builtEvent = eventBuilder.build();
164172
Sentry.capture(builtEvent);
165173
} else {

0 commit comments

Comments
 (0)