From a7c11f6438ebb7c7c3ebc06887a870b3209a32c9 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk <3636685+Palid@users.noreply.github.com> Date: Sun, 22 Mar 2020 17:28:23 +0100 Subject: [PATCH] fix: ios - untracable crashes when URL is not parsable (#183) Due to NSURL checking compliance with RFC 2396 while parsing the url, sometimes when the URL is not compilant with the RFC it is considered `nil` and code throws this error. The problem is that this error is not caught anywhere, therefore crashing with a very unhelpful stack trace, as seen here: https://github.com/Vydia/react-native-background-upload/issues/121 --- ios/VydiaRNFileUploader.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ios/VydiaRNFileUploader.m b/ios/VydiaRNFileUploader.m index e36efab7..c60c2d1a 100644 --- a/ios/VydiaRNFileUploader.m +++ b/ios/VydiaRNFileUploader.m @@ -156,9 +156,9 @@ - (void)copyAssetToFile: (NSString *)assetUrl completionHandler: (void(^)(NSStri @try { NSURL *requestUrl = [NSURL URLWithString: uploadUrl]; if (requestUrl == nil) { - @throw @"Request cannot be nil"; + return reject(@"RN Uploader", @"URL not compliant with RFC 2396", nil); } - + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:requestUrl]; [request setHTTPMethod: method];