jens@7: // jens@7: // URLUtils.m jens@7: // Cloudy jens@7: // jens@7: // Created by Jens Alfke on 4/28/08. jens@7: // Copyright 2008 __MyCompanyName__. All rights reserved. jens@7: // jens@7: jens@7: #import "URLUtils.h" jens@7: jens@7: jens@7: @implementation NSHTTPURLResponse (MYUtilities) jens@7: jens@7: jens@7: - (NSError*) HTTPError jens@7: { jens@7: // HTTP status >= 300 is considered an error: jens@7: int status = self.statusCode; jens@7: if( status >= 300 ) { jens@7: NSString *reason = NSLocalizedStringFromTable( @"HTTP_ERROR_MESSAGE",@"UKCrashReporter",@""); jens@7: reason = [NSHTTPURLResponse localizedStringForStatusCode: status]; jens@7: NSDictionary *info = $dict({NSLocalizedFailureReasonErrorKey,reason}); jens@7: return [NSError errorWithDomain: MyHTTPErrorDomain code: status userInfo: info]; jens@7: } else jens@7: return nil; jens@7: } jens@7: jens@7: jens@7: NSString* const MyHTTPErrorDomain = @"HTTP"; jens@7: jens@7: jens@7: @end