Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix uncaught HTTP exception #289

Merged
merged 1 commit into from
Mar 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions Source/ARTHttp.m
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,7 @@ - (void)executeRequest:(NSMutableURLRequest *)request completion:(void (^)(NSHTT
request.HTTPBody = artRequest.body;
[self.logger debug:@"ARTHttp: makeRequest %@", [request allHTTPHeaderFields]];

CFRunLoopRef rl = CFRunLoopGetCurrent();
CFRetain(rl);
__block CFRunLoopRef rl = CFRunLoopGetCurrent();

[self.urlSession get:request completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
Expand All @@ -243,7 +242,6 @@ - (void)executeRequest:(NSMutableURLRequest *)request completion:(void (^)(NSHTT
}
}
CFRunLoopWakeUp(rl);
CFRelease(rl);
}];
return nil;
}
Expand Down
61 changes: 34 additions & 27 deletions Tests/ARTTestUtil.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,39 +82,46 @@ + (void)setupApp:(ARTClientOptions *)options withDebug:(BOOL)debug withAlteratio
__block CFRunLoopRef rl = CFRunLoopGetCurrent();

[[[ARTURLSessionServerTrust alloc] init] get:req completion:^(NSHTTPURLResponse *response, NSData *data, NSError *error) {
if (response.statusCode < 200 || response.statusCode >= 300) {
NSLog(@"Status Code: %ld", (long)response.statusCode);
NSLog(@"Body: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
cb(nil);
return;
}

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if (!json) {
NSLog(@"No response");
return;
}
else if (debug) {
NSLog(@"Response: %@", json);
}
@try {
if (response.statusCode < 200 || response.statusCode >= 300) {
NSLog(@"Status Code: %ld", (long)response.statusCode);
NSLog(@"Body: %@", [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]);
CFRunLoopPerformBlock(rl, kCFRunLoopDefaultMode, ^{
cb(nil);
});
return;
}

NSDictionary *key = json[@"keys"][(alt == TestAlterationRestrictCapability ? 1 :0)];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
if (!json) {
NSLog(@"No response");
CFRunLoopPerformBlock(rl, kCFRunLoopDefaultMode, ^{
cb(nil);
});
return;
}
else if (debug) {
NSLog(@"Response: %@", json);
}

ARTClientOptions *testOptions = [options copy];
NSDictionary *key = json[@"keys"][(alt == TestAlterationRestrictCapability ? 1 :0)];

// TODO: assign key[@"capability"]
ARTClientOptions *testOptions = [options copy];

testOptions.key = key[@"keyStr"];
testOptions.key = key[@"keyStr"];

if (alt == TestAlterationBadKeyId || alt == TestAlterationBadKeyValue)
{
testOptions.key = @"badKey";
if (alt == TestAlterationBadKeyId || alt == TestAlterationBadKeyValue)
{
testOptions.key = @"badKey";
}

CFRunLoopPerformBlock(rl, kCFRunLoopDefaultMode, ^{
cb(testOptions);
});
}
@finally {
CFRunLoopWakeUp(rl);
}

CFRunLoopPerformBlock(rl, kCFRunLoopDefaultMode, ^{
cb(testOptions);
});
CFRunLoopWakeUp(rl);
}];
}

Expand Down