Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
improved http response logging
Browse files Browse the repository at this point in the history
  • Loading branch information
calebd committed Dec 16, 2010
1 parent 7380f78 commit 52a8ed9
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions hoptoadnotifier/HTNotifier.m
Expand Up @@ -149,7 +149,6 @@ - (void)postNoticesWithPaths:(NSArray *)paths {

// get notice payload
HTNotice *notice = [HTNotice readFromFile:noticePath];
NSLog(@"%@", [notice hoptoadXMLString]);
NSData *xmlData = [notice hoptoadXMLData];

// create url request
Expand All @@ -160,36 +159,36 @@ - (void)postNoticesWithPaths:(NSArray *)paths {
[request setHTTPMethod:@"POST"];
[request setHTTPBody:xmlData];

// create connection
// perform request
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *responseBody = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
[request release];
NSInteger statusCode = [response statusCode];
NSString *responseString = [[[NSString alloc] initWithData:responseBody encoding:NSUTF8StringEncoding] autorelease];

// error
if (error != nil) {
if (error == nil) {
[[NSFileManager defaultManager] removeItemAtPath:noticePath error:nil];
}
else {
HTLog(@"encountered error while posting notice\n%@", error);
}

// response
// all went well
if (statusCode == 200) {
HTLog(@"crash report posted");
}
else if (responseString == nil) {
HTLog(@"unexpected response from Hoptoad\nstatus code:%d", statusCode);
else if (responseBody == nil) {
HTLog(@"unexpected response\nstatus code:%d", statusCode);
}
else {
HTLog(@"unexpected response from Hoptoad\nstatus code:%d\nresponse body:%@",
NSString *responseString = [[NSString alloc] initWithData:responseBody
encoding:NSUTF8StringEncoding];
HTLog(@"unexpected response\nstatus code:%d\nresponse body:%@",
statusCode,
responseString);
[responseString release];
}

// delete report
[[NSFileManager defaultManager] removeItemAtPath:noticePath error:nil];
}
}
- (BOOL)isHoptoadReachable {
Expand Down

0 comments on commit 52a8ed9

Please sign in to comment.