Skip to content

Commit

Permalink
Merge pull request RestKit#83 from sixten/0.9-error-handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Watters committed May 11, 2011
2 parents 8d7a490 + 40c4940 commit e5093a3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Code/CoreData/RKManagedObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ + (NSFetchRequest*)fetchRequest {
+ (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
}
Expand Down
2 changes: 1 addition & 1 deletion Code/CoreData/RKManagedObjectSeeder.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ - (void)seedObjectsFromFile:(NSString*)fileName toClass:(Class<RKObjectMappable>
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];
Expand Down
2 changes: 2 additions & 0 deletions Code/CoreData/RKManagedObjectStore.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ - (NSError*)save {

NSDictionary* userInfo = [NSDictionary dictionaryWithObject:error forKey:@"error"];
[[NSNotificationCenter defaultCenter] postNotificationName:RKManagedObjectStoreDidFailSaveNotification object:self userInfo:userInfo];

return error;
}
}
@catch (NSException* e) {
Expand Down
9 changes: 6 additions & 3 deletions Code/Network/RKParamsAttachment.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,12 @@ - (id)initWithName:(NSString*)name file:(NSString*)filePath {
_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);
}
}
Expand Down
16 changes: 9 additions & 7 deletions Code/Network/RKRequest.m
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ - (void)sendAsynchronously {

- (RKResponse*)sendSynchronously {
NSURLResponse* URLResponse = nil;
NSError* error = nil;
NSError* error;
NSData* payload = nil;
RKResponse* response = nil;

Expand All @@ -266,13 +266,15 @@ - (RKResponse*)sendSynchronously {
}

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:
Expand Down

0 comments on commit e5093a3

Please sign in to comment.