From b4ad5157924bb7af289ce68e4e9f008fd6baa90e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Mon, 14 Apr 2014 11:17:22 -0400 Subject: [PATCH] don't report intentionally cancelled HTTP requests as error on os x + ios --- ios/MBXViewController.mm | 5 +++++ macosx/main.mm | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/ios/MBXViewController.mm b/ios/MBXViewController.mm index f2ed117d4..3e52db752 100644 --- a/ios/MBXViewController.mm +++ b/ios/MBXViewController.mm @@ -479,6 +479,11 @@ namespace llmr { dispatch_async(queue, ^(){ [[NSNotificationCenter defaultCenter] postNotificationName:MBXUpdateActivityNotification object:nil]; + if ([error code] == NSURLErrorCancelled) { + // We intentionally cancelled this request. Do nothing. + return; + } + Response res; if ( ! error && [response isKindOfClass:[NSHTTPURLResponse class]]) diff --git a/macosx/main.mm b/macosx/main.mm index 705bff8ff..269d2bc6e 100644 --- a/macosx/main.mm +++ b/macosx/main.mm @@ -48,12 +48,19 @@ Request *request_http(std::string url, std::function background { NSURLSessionDataTask *task = [[NSURLSession sharedSession] dataTaskWithURL:[NSURL URLWithString:@(url.c_str())] completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { + if ([error code] == NSURLErrorCancelled) { + // We intentionally cancelled this request. Do nothing. + return; + } + Response res; if ( ! error && [response isKindOfClass:[NSHTTPURLResponse class]]) { res.code = [(NSHTTPURLResponse *)response statusCode]; res.body = { (const char *)[data bytes], [data length] }; + } else { + NSLog(@"http error (%s): %@", url.c_str(), [error localizedDescription]); } background_function(res);