diff --git a/android/src/main/java/com/instabug/reactlibrary/RNInstabugCrashReportingModule.java b/android/src/main/java/com/instabug/reactlibrary/RNInstabugCrashReportingModule.java index f7c076253..847c54751 100644 --- a/android/src/main/java/com/instabug/reactlibrary/RNInstabugCrashReportingModule.java +++ b/android/src/main/java/com/instabug/reactlibrary/RNInstabugCrashReportingModule.java @@ -94,22 +94,39 @@ public void sendHandledJSCrash(final String exceptionObject, @Nullable final Rea try { final JSONObject jsonObject = new JSONObject(exceptionObject); MainThreadHandler.runOnMainThread(new Runnable() { - @Override - public void run() { + @ReactMethod + public void sendNativeNonFatal(@Nullable ReadableMap params) { + if (params == null) { + // Optionally log or handle the missing argument case gracefully + return; + } try { - Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class, - Map.class, JSONObject.class, IBGNonFatalException.Level.class); + JSONObject jsonObject = new JSONObject(params.hasKey("jsonObject") ? params.getString("jsonObject") : "{}"); + IBGNonFatalException.Level nonFatalExceptionLevel = IBGNonFatalException.Level.ERROR; + if (params.hasKey("level")) { + String level = params.getString("level"); + if (ArgsRegistry.nonFatalExceptionLevel != null) { + nonFatalExceptionLevel = ArgsRegistry.nonFatalExceptionLevel.getOrDefault(level, IBGNonFatalException.Level.ERROR); + } + } + Map userAttributesMap = null; + if (params.hasKey("userAttributes")) { + ReadableMap userAttributes = params.getMap("userAttributes"); + userAttributesMap = userAttributes != null ? userAttributes.toHashMap() : null; + } + JSONObject fingerprintObj = null; + if (params.hasKey("fingerprint")) { + String fingerprint = params.getString("fingerprint"); + if (fingerprint != null) { + fingerprintObj = CrashReporting.getFingerprintObject(fingerprint); + } + } + Method method = getMethod(Class.forName("com.instabug.crash.CrashReporting"), "reportException", JSONObject.class, boolean.class, Map.class, JSONObject.class, IBGNonFatalException.Level.class); if (method != null) { - IBGNonFatalException.Level nonFatalExceptionLevel = ArgsRegistry.nonFatalExceptionLevel.getOrDefault(level, IBGNonFatalException.Level.ERROR); - Map userAttributesMap = userAttributes == null ? null : userAttributes.toHashMap(); - JSONObject fingerprintObj = fingerprint == null ? null : CrashReporting.getFingerprintObject(fingerprint); - method.invoke(null, jsonObject, true, userAttributesMap, fingerprintObj, nonFatalExceptionLevel); - RNInstabugReactnativeModule.clearCurrentReport(); } - } catch (ClassNotFoundException | IllegalAccessException | - InvocationTargetException e) { + } catch (Exception e) { e.printStackTrace(); } }