Merge pull request #83 from sixten/0.9-error-handling

This commit is contained in:
Blake Watters
2011-05-10 17:58:46 -07:00
5 changed files with 19 additions and 12 deletions

View File

@@ -36,7 +36,7 @@
+ (NSArray*)objectsWithFetchRequest:(NSFetchRequest*)fetchRequest {
NSError* error = nil;
NSArray* objects = [[RKManagedObject managedObjectContext] executeFetchRequest:fetchRequest error:&error];
if (error != nil) {
if (objects == nil) {
NSLog(@"Error: %@", [error localizedDescription]);
// TODO: Error handling
}

View File

@@ -89,7 +89,7 @@ NSString* const RKDefaultSeedDatabaseFileName = @"RKSeedDatabase.sqlite";
NSString* filePath = [[NSBundle mainBundle] pathForResource:fileName ofType:nil];
NSString* payload = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:&error];
if (nil == error) {
if (payload != nil) {
// TODO: When we support multiple parsers, we should auto-detect the MIME Type from the file extension
// and pass it through to the mapper
id objects = [_manager.mapper parseString:payload];

View File

@@ -107,6 +107,8 @@ static NSString* const kRKManagedObjectContextKey = @"RKManagedObjectContext";
NSDictionary* userInfo = [NSDictionary dictionaryWithObject:error forKey:@"error"];
[[NSNotificationCenter defaultCenter] postNotificationName:RKManagedObjectStoreDidFailSaveNotification object:self userInfo:userInfo];
return error;
}
}
@catch (NSException* e) {

View File

@@ -65,9 +65,12 @@ extern NSString* const kRKStringBoundary;
_MIMEType = [[self mimeTypeForExtension:[filePath pathExtension]] retain];
_bodyStream = [[NSInputStream inputStreamWithFileAtPath:filePath] retain];
NSError* error = nil;
_bodyLength = [[[[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error] objectForKey:NSFileSize] unsignedIntegerValue];
if (error) {
NSError* error;
NSDictionary* attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filePath error:&error];
if (attributes) {
_bodyLength = [[attributes objectForKey:NSFileSize] unsignedIntegerValue];
}
else {
NSLog(@"Encountered an error while determining file size: %@", error);
}
}

View File

@@ -248,7 +248,7 @@
- (RKResponse*)sendSynchronously {
NSURLResponse* URLResponse = nil;
NSError* error = nil;
NSError* error;
NSData* payload = nil;
RKResponse* response = nil;
@@ -266,13 +266,15 @@
}
payload = [NSURLConnection sendSynchronousRequest:_URLRequest returningResponse:&URLResponse error:&error];
if (payload != nil) error = nil;
response = [[[RKResponse alloc] initWithSynchronousRequest:self URLResponse:URLResponse body:payload error:error] autorelease];
if (error) {
[self didFailLoadWithError:error];
} else {
[self didFinishLoad:response];
}
if (payload == nil) {
[self didFailLoadWithError:error];
} else {
[self didFinishLoad:response];
}
} else {
NSString* errorMessage = [NSString stringWithFormat:@"The client is unable to contact the resource at %@", [[self URL] absoluteString]];
NSDictionary *userInfo = [NSDictionary dictionaryWithObjectsAndKeys: