react-native-firebase/ios/RNFirebase/RNFirebaseErrors.m

53 lines
1.7 KiB
Mathematica
Raw Normal View History

2017-03-09 15:26:28 +00:00
#import "RNFirebaseErrors.h"
@implementation RNFirebaseErrors
RCT_EXPORT_MODULE(RNFirebaseErrors);
+ (void) handleException:(NSException *)exception
withCallback:(RCTResponseSenderBlock)callback
{
NSString *errDesc = [exception description];
NSLog(@"An error occurred: %@", errDesc);
// No user is signed in.
NSDictionary *err = @{
@"error": @"No user signed in",
@"description": errDesc
};
callback(@[err]);
}
+ (NSDictionary *) handleFirebaseError:(NSString *) name
error:(NSError *) error
withUser:(FIRUser *) user
{
NSMutableDictionary *err = [NSMutableDictionary dictionaryWithObjectsAndKeys:
name, @"name",
@([error code]), @"code",
[error localizedDescription], @"rawDescription",
[[error userInfo] description], @"userInfo",
nil];
NSString *description = @"Unknown error";
switch (error.code) {
case FIRAuthErrorCodeInvalidEmail:
description = @"Invalid email";
break;
case FIRAuthErrorCodeUserNotFound:
description = @"User not found";
break;
case FIRAuthErrorCodeNetworkError:
description = @"Network error";
break;
case FIRAuthErrorCodeInternalError:
description = @"Internal error";
break;
default:
break;
}
[err setValue:description forKey:@"description"];
return [NSDictionary dictionaryWithDictionary:err];
}
@end