From d4aa2e8b2818356639133556a27b91131ba48972 Mon Sep 17 00:00:00 2001 From: Dariusz Niemczyk <3636685+Palid@users.noreply.github.com> Date: Wed, 22 Jan 2020 15:26:31 +0100 Subject: [PATCH] Fix untracable crashes when URL is not parsable 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];