Created
November 20, 2012 00:56
-
-
Save tibo/4115246 to your computer and use it in GitHub Desktop.
handle error by inheriting viewcontrollers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface LoginViewController : ParentViewController () | |
@end | |
// ... | |
@implementation | |
#pragma mark LoginServiceDelegate | |
-(void)loginDidFailWithError:(NSError *)loginError | |
{ | |
[self handleError:loginError]; | |
} | |
// overwrite error handling | |
-(void)handleError:(NSError *)error | |
{ | |
if (error.code == INVALIDE_PASSWORD_ERROR_CODE) | |
{ | |
// manage invalid password error case... | |
return; | |
} | |
[super handleError:error]; | |
} | |
//... | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface ParentViewController : UIViewController () | |
-(void)handleError:(NSError *)error; | |
@end | |
//... | |
@implementation ParentViewController | |
-(void)handleError:(NSError *)error | |
{ | |
NSLog(@"%@",[error localizedDescription]); | |
NSString *message; | |
if (error.code == CUSTOM_NETWORK_ERROR_CODE) | |
{ // handle specific error kind | |
message = @"Network Error"; | |
} | |
else if (error.code == KNOWN_SERVER_ERROR_CODE) | |
{ // known error to display as if from the server | |
message = error.domain; | |
} | |
else | |
{ //generic error message | |
message = @"Something went wrong"; | |
} | |
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" | |
message:message | |
delegate:nil | |
cancelButtonTitle:@"OK" | |
otherButtonTitle:nil]; | |
} | |
//... | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment