Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,15 @@ - (id)responseObjectForResponse:(NSURLResponse *)response
(*error) = newError;
}

NSAssert(([responseObject isKindOfClass:[NSDictionary class]] ||
[responseObject isKindOfClass:[NSArray class]]),
@"Response object should be of type array or dictionary.");
// Verify that the server responded in an expected manner.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assertion will only get triggered in DEBUG builds, so I don't think this is a terrible thing to do. However, I could be sold on having an error condition as a better way to handle this. An error is also more consistent with the way the rest of the library works.

if (!([responseObject isKindOfClass:[NSDictionary class]]) &&
!([responseObject isKindOfClass:[NSArray class]])) {

(*error) = [MMRecord errorWithMMRecordCode:MMRecordErrorCodeInvalidResponseFormat
description:[NSString stringWithFormat:@"The response object should be an array or dictionary. The returned response object type was: %@", NSStringFromClass([responseObject class])]];

return nil;
}

NSEntityDescription *initialEntity = [self.entityMapper recordResponseSerializer:self
entityForResponse:response
Expand Down
4 changes: 4 additions & 0 deletions Source/MMRecord/MMRecord.m
Original file line number Diff line number Diff line change
Expand Up @@ -1037,6 +1037,10 @@ + (NSString *)descriptionForMCErrorCode:(MMRecordErrorCode)errorCode {
result = NSLocalizedString(@"Invalid Entity Description. This could be because this record class is not used in your managed object model, or because your persistent store coordinator or managed object model are not defined properly. An entity description is required for creating records.",
@"This could be because this record class is not used in your managed object model, or because your persistent store coordinator or managed object model are not defined properly. An entity description is required for creating records.");
break;
case MMRecordErrorCodeInvalidResponseFormat:
result = NSLocalizedString(@"Invalid Response Format.",
@"The server response was in an unexpected format that could not be handled by MMRecord.");
break;
default:
case MMRecordErrorCodeUnknown:
result = NSLocalizedString(@"Unknown Error",
Expand Down