Hook EarlyJsErrorHandler

Summary:
Hoop up EarlyJsErrorHandler so we could pass js error data to object-c to report.

Changelog:
[iOS][Chagned] - Add function to report early js errors

Reviewed By: RSNara

Differential Revision: D34096343

fbshipit-source-id: fdbc6ea5d1f3cc6ab55fcd22b48bbe8fb1f1ca8f
This commit is contained in:
Lulu Wu
2022-03-10 10:25:32 -08:00
committed by Facebook GitHub Bot
parent 325be429fd
commit 1804951595
2 changed files with 23 additions and 1 deletions
+2 -1
View File
@@ -6,8 +6,8 @@
*/
#import <Foundation/Foundation.h>
#import <React/RCTBridgeModule.h>
#import <string>
NS_ASSUME_NONNULL_BEGIN
@@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
- (void)reportFatalException:(nullable NSString *)message
stack:(nullable NSArray<NSDictionary *> *)stack
exceptionId:(double)exceptionId;
- (void)reportEarlyJsException:(std::string)errorMap;
@property (nonatomic, weak) id<RCTExceptionsManagerDelegate> delegate;
+21
View File
@@ -138,6 +138,27 @@ RCT_EXPORT_METHOD(reportException : (JS::NativeExceptionsManager::ExceptionData
}
}
- (void)reportEarlyJsException:(std::string)errorMap
{
NSString *errprStr = [NSString stringWithUTF8String:errorMap.c_str()];
NSData *jsonData = [errprStr dataUsingEncoding:NSUTF8StringEncoding];
NSError *jsonError;
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData
options:NSJSONWritingPrettyPrinted
error:&jsonError];
NSString *message = [dict objectForKey:@"message"];
double exceptionId = [[dict objectForKey:@"id"] doubleValue];
NSArray *stack = [dict objectForKey:@"stack"];
BOOL isFatal = [[dict objectForKey:@"isFatal"] boolValue];
if (isFatal) {
[self reportFatalException:message stack:stack exceptionId:exceptionId];
} else {
[self reportSoftException:message stack:stack exceptionId:exceptionId];
}
}
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
(const facebook::react::ObjCTurboModule::InitParams &)params
{