diff --git a/packages/react-native/Libraries/Network/RCTNetworkTask.mm b/packages/react-native/Libraries/Network/RCTNetworkTask.mm index fc2c6dcad9f51e..47a2e92d0d58dd 100644 --- a/packages/react-native/Libraries/Network/RCTNetworkTask.mm +++ b/packages/react-native/Libraries/Network/RCTNetworkTask.mm @@ -164,7 +164,21 @@ - (void)URLRequest:(id)requestToken didReceiveData:(NSData *)data if (!_data) { _data = [NSMutableData new]; } - [_data appendData:data]; + @try { + [_data appendData:data]; + } @catch (NSException *exception) { + _status = RCTNetworkTaskFinished; + if (_completionBlock) { + RCTURLRequestCompletionBlock completionBlock = _completionBlock; + [self dispatchCallback:^{ + completionBlock( + self->_response, nil, RCTErrorWithMessage(exception.reason ?: @"Request's received data too long.")); + }]; + } + [self invalidate]; + return; + } + length = _data.length; }