MM-21582 Parse payload safely to report Sentry exception with needed info (#4052)

Users are hitting legitimate exceptions when using the Android Share extension.

However, in some cases where the channel ID isn't available from the user's actions that triggered the exception, the Sentry error reporting message payload can't be successfully formed and it bombs.

This commit allows Sentry's payload to be successfully formed, so that we can now see the actual underlying exception (with its associated user data) in Sentry. The single, catch-all `NoSuchKeyException` should now stop, and be replaced by a few new Sentry exception reports to analyze and tackle individually.
This commit is contained in:
Mattermost Build 2020-03-19 18:22:01 +01:00 committed by GitHub
parent 1a831aac66
commit dfc4d82452
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -194,8 +194,12 @@ public class ShareModule extends ReactContextBaseJavaModule {
JSONObject json = new JSONObject();
try {
json.put("user_id", data.getString("currentUserId"));
json.put("channel_id", data.getString("channelId"));
json.put("message", data.getString("value"));
if (data.hasKey("channel_id")) {
json.put("channel_id", data.getString("channelId"));
}
if (data.hasKey("value")) {
json.put("message", data.getString("value"));
}
} catch (JSONException e) {
e.printStackTrace();
}