From 6d92d7f422a35f2b52efed0336216aa7406616de Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Fri, 25 Sep 2009 14:43:45 -0400 Subject: [PATCH] Sync changes to AnselKit from iPhoto2Ansel. Don't assume we have a server response. --- ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m | 39 ++++++++++++++-------- 1 file changed, 25 insertions(+), 14 deletions(-) diff --git a/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m b/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m index 56ad2f77d..347d5644f 100644 --- a/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m +++ b/ApertureToAnselExportPlugin/TURAnselKit/TURAnsel.m @@ -166,34 +166,45 @@ CFRelease(request); // Check out the results if (WSMethodResultIsFault((CFDictionaryRef) result)) { - NSError *error; - CFHTTPMessageRef response = (CFHTTPMessageRef)[result objectForKey:(id)kWSHTTPResponseMessage]; - int resStatusCode = CFHTTPMessageGetResponseStatusCode(response); - NSString *resStatusLine = (NSString *)CFHTTPMessageCopyResponseStatusLine(response); - if (resStatusCode == 401) { - error = [NSError errorWithDomain: @"TURAnsel" - code: resStatusCode - userInfo: [NSDictionary dictionaryWithObjectsAndKeys: resStatusLine, @"NSLocalizedDescriptionKey", nil]]; + // We might not have a response at all (server might be unreachable) + if (response) { + int resStatusCode = CFHTTPMessageGetResponseStatusCode(response); + NSString *resStatusLine = (NSString *)CFHTTPMessageCopyResponseStatusLine(response); + if (resStatusCode == 401) { + error = [NSError errorWithDomain: @"TURAnsel" + code: resStatusCode + userInfo: [NSDictionary dictionaryWithObjectsAndKeys: resStatusLine, @"NSLocalizedDescriptionKey", nil]]; + } else { + NSNumber *faultCode = [result objectForKey: (NSString *)kWSFaultCode]; + NSString *faultString = [result objectForKey: (NSString *)kWSFaultString]; + NSLog(@"faultCode: %@ faultString: %@", faultCode, faultString); + error = [NSError errorWithDomain: @"TURAnsel" + code: [faultCode intValue] + userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat: @"There was an error contacting the Ansel server: %@, %@", resStatusLine, faultString], @"NSLocalizedDescriptionKey", nil]]; + + + } + [resStatusLine release]; } else { + // No response NSNumber *faultCode = [result objectForKey: (NSString *)kWSFaultCode]; NSString *faultString = [result objectForKey: (NSString *)kWSFaultString]; NSLog(@"faultCode: %@ faultString: %@", faultCode, faultString); error = [NSError errorWithDomain: @"TURAnsel" code: [faultCode intValue] - userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat: @"%@, %@", resStatusLine, faultString], @"NSLocalizedDescriptionKey", nil]]; - - - } + userInfo: [NSDictionary dictionaryWithObjectsAndKeys: [NSString stringWithFormat: @"There was an error contacting the Ansel server: %@", faultString], @"NSLocalizedDescriptionKey", nil]]; + + } + if ([[self delegate] respondsToSelector: @selector(TURAnselHadError:)]) { [[self delegate] TURAnselHadError: error]; } - [resStatusLine release]; [result autorelease]; return nil; + } - CFHTTPMessageRef response = (CFHTTPMessageRef)[result objectForKey:(id)kWSHTTPResponseMessage]; int resStatusCode = CFHTTPMessageGetResponseStatusCode(response); NSLog(@"ResponseCode: %d", resStatusCode); -- 2.11.0