Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed server response handling from NSException to NSError #54

Merged
merged 4 commits into from
Apr 2, 2014

Conversation

jhilts
Copy link
Contributor

@jhilts jhilts commented Apr 1, 2014

If the server were to return something unexpected, it is often recoverable; as an NSException the app would simply crash.

@@ -131,9 +131,18 @@ - (id)responseObjectForResponse:(NSURLResponse *)response
(*error) = newError;
}

NSAssert(([responseObject isKindOfClass:[NSDictionary class]] ||
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.

@jhilts
Copy link
Contributor Author

jhilts commented Apr 1, 2014

That's fair, I will update the header ASAP. Thanks!

@cnstoll cnstoll added this to the 1.3.1 milestone Apr 1, 2014
@jhilts
Copy link
Contributor Author

jhilts commented Apr 1, 2014

The already-defined MMRecordErrorCodeInvalidResponseFormat seems applicable to this case, do you agree?

@cnstoll
Copy link
Contributor

cnstoll commented Apr 1, 2014

Yeah I think so too 👍

@jhilts
Copy link
Contributor Author

jhilts commented Apr 1, 2014

Please let me know if there are any other recommended changes.

@@ -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 responded in a manner which could not be processed by the serializer.");
Copy link
Contributor

Choose a reason for hiding this comment

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

Subtle point, but MMRecord.m technically doesn't know anything about the AFResponseSerializer. Lets change this string to:

"The server response was in an unexpected format that could not be handled by MMRecord."

@jhilts
Copy link
Contributor Author

jhilts commented Apr 1, 2014

Done!

@cnstoll
Copy link
Contributor

cnstoll commented Apr 2, 2014

Hehe, good catch Brian. I did not notice the encompassing () around the or clause, hence the confusion.

cnstoll added a commit that referenced this pull request Apr 2, 2014
Changed server response handling from NSException to NSError
@cnstoll cnstoll merged commit 113e191 into mutualmobile:master Apr 2, 2014
@cnstoll
Copy link
Contributor

cnstoll commented Apr 2, 2014

Merged. Thanks Jeremy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants