don't report intentionally cancelled HTTP requests as error on os x + ios

This commit is contained in:
Konstantin Käfer
2014-04-14 11:17:22 -04:00
parent e34fc8a303
commit b4ad515792
2 changed files with 12 additions and 0 deletions

View File

@@ -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]])

View File

@@ -48,12 +48,19 @@ Request *request_http(std::string url, std::function<void(Response&)> 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);