samsymons/RedditKit — pull request #31 by rickharrison (2014-03-14 08:37:44+00:00)
Title: Added error for SUBREDDIT_NOEXIST

I added an error for `SUBREDDIT_NOEXIST` as well as fixing a bug with subreddit names when submitting.

I'm trying to figure out the best way to make the error handling stronger. Do you think we should set up some sort of catch for errors that are not already defined in code? Do you have it set up the way it is now, because of the odd json structure that reddit passes back for errors? What do you think of adding something like this:

```objective-c
+ (NSError *)errorFromResponseObject:(id)responseObject {
NSParameterAssert(responseObject);

if ([responseObject isKindOfClass:[NSDictionary class]])
{
NSDictionary *response = responseObject;
NSArray *errors = [response valueForKeyPath:@"json.errors"];

if ([errors isKindOfClass:[NSArray class]] && [errors count] > 0)
{
id firstObject = [errors firstObject];

if ([firstObject isKindOfClass:[NSArray class]] && [firstObject count] > 1)
{
NSString *firstString = [firstObject firstObject];
NSString *secondString = [firstObject objectAtIndex:1];

if ([firstString isKindOfClass:[NSString class]] && [secondString isKindOfClass:[NSString class]])
{

}

NSDictionary *userInfo = [RKClient userInfoWithDescription:firstString failureReason:secondString];
return [NSError errorWithDomain:RKClientErrorDomain code:RKClientErrorAPIError userInfo:userInfo];
}
}
}

return nil;
}
```

I put a ton of checks in there to prevent any sort of crashes that could occur from reddit changing their json structure. Let me know your thoughts. Hopefully if we bounce some ideas around we can improve this part of the code. If you'd like to chat via IRC or something like that, let me know.