Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Display better error messages

  • Loading branch information...
commit a2d9205a9a649f00ab06ab16c8cc5cb8e9da6f3b 1 parent 958fa83
@austintaylor austintaylor authored
View
4 Categories/NSError+UVExtras.m
@@ -38,7 +38,9 @@ - (BOOL)isUVRecordInvalidForField:(NSString *)field withMessage:(NSString *)mess
if (![self isUVRecordInvalid])
return NO;
- NSString *errorStr = [[self userInfo] objectForKey:field];
+ NSString *errorStr = [[self userInfo] objectForKey:field];
+ if (!errorStr)
+ return NO;
return [errorStr rangeOfString:message].location != NSNotFound;
}
View
30 Classes/UVBaseViewController.m
@@ -93,31 +93,45 @@ - (void)setVoteLabelTextAndColorForVotesRemaining:(NSInteger)votesRemaining labe
label.font = [UIFont boldSystemFontOfSize:14];
label.text = @"You will need to sign in to vote.";
label.textColor = [UVStyleSheet alertTextColor];
- }
+ }
}
-- (void)showErrorAlertViewWithMessage:(NSString *)message
-{
+- (void)showErrorAlertViewWithMessage:(NSString *)message {
[self setupErrorAlertViewWithMessage:message];
[self setupErrorAlertViewDelegate];
[errorAlertView show];
}
-- (UIAlertView *)setupErrorAlertViewWithMessage:(NSString *)message
-{
+- (UIAlertView *)setupErrorAlertViewWithMessage:(NSString *)message {
self.errorAlertView = [[[UIAlertView alloc] initWithTitle:@"Error" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
return errorAlertView;
}
-- (void)setupErrorAlertViewDelegate
-{
+- (void)setupErrorAlertViewDelegate {
}
- (void)didReceiveError:(NSError *)error {
[self hideActivityIndicator];
NSString *msg = nil;
if ([UVNetworkUtils hasInternetAccess] && ![error isConnectionError]) {
- msg = @"Sorry, there was an error in the application.";
+ NSDictionary *userInfo = [error userInfo];
+ for (NSString *key in [userInfo allKeys]) {
+ if ([key isEqualToString:@"message"] || [key isEqualToString:@"type"])
+ continue;
+ NSString *displayKey = nil;
+ if ([key isEqualToString:@"display_name"])
+ displayKey = @"User name";
+ else
+ displayKey = [[key stringByReplacingOccurrencesOfString:@"_" withString:@" "] capitalizedString];
+
+ // Suggestion title has custom messages
+ if ([key isEqualToString:@"title"])
+ msg = [userInfo valueForKey:key];
+ else
+ msg = [NSString stringWithFormat:@"%@ %@", displayKey, [userInfo valueForKey:key], nil];
+ }
+ if (!msg)
+ msg = @"Sorry, there was an error in the application.";
} else {
msg = @"There appears to be a problem with your network connection, please check your connectivity and try again.";
}
View
6 Classes/UVResponseDelegate.m
@@ -42,9 +42,9 @@ - (void)restConnection:(NSURLConnection *)connection didReturnResource:(id)resou
if (statusCode >= 400) {
NSDictionary *userInfo = nil;
-
- if ([resource respondsToSelector:@selector(objectForKey:)])
- userInfo = [resource objectForKey:@"errors"];
+
+ if ([resource respondsToSelector:@selector(objectForKey:)])
+ userInfo = [resource objectForKey:@"errors"];
NSError *error = [NSError errorWithDomain:@"uservoice" code:statusCode userInfo:userInfo];
[modelClass didReceiveError:error callback:object];
Please sign in to comment.
Something went wrong with that request. Please try again.