Skip to content

Commit 1804951

Browse files
luluwu2032facebook-github-bot
authored andcommitted
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
1 parent 325be42 commit 1804951

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

React/CoreModules/RCTExceptionsManager.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
*/
77

88
#import <Foundation/Foundation.h>
9-
109
#import <React/RCTBridgeModule.h>
10+
#import <string>
1111

1212
NS_ASSUME_NONNULL_BEGIN
1313

@@ -37,6 +37,7 @@ NS_ASSUME_NONNULL_BEGIN
3737
- (void)reportFatalException:(nullable NSString *)message
3838
stack:(nullable NSArray<NSDictionary *> *)stack
3939
exceptionId:(double)exceptionId;
40+
- (void)reportEarlyJsException:(std::string)errorMap;
4041

4142
@property (nonatomic, weak) id<RCTExceptionsManagerDelegate> delegate;
4243

React/CoreModules/RCTExceptionsManager.mm

+21
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,27 @@ - (void)reportFatal:(NSString *)message stack:(NSArray<NSDictionary *> *)stack e
138138
}
139139
}
140140

141+
- (void)reportEarlyJsException:(std::string)errorMap
142+
{
143+
NSString *errprStr = [NSString stringWithUTF8String:errorMap.c_str()];
144+
NSData *jsonData = [errprStr dataUsingEncoding:NSUTF8StringEncoding];
145+
NSError *jsonError;
146+
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:jsonData
147+
options:NSJSONWritingPrettyPrinted
148+
error:&jsonError];
149+
150+
NSString *message = [dict objectForKey:@"message"];
151+
double exceptionId = [[dict objectForKey:@"id"] doubleValue];
152+
NSArray *stack = [dict objectForKey:@"stack"];
153+
BOOL isFatal = [[dict objectForKey:@"isFatal"] boolValue];
154+
155+
if (isFatal) {
156+
[self reportFatalException:message stack:stack exceptionId:exceptionId];
157+
} else {
158+
[self reportSoftException:message stack:stack exceptionId:exceptionId];
159+
}
160+
}
161+
141162
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
142163
(const facebook::react::ObjCTurboModule::InitParams &)params
143164
{

0 commit comments

Comments
 (0)