-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathFirestackErrors.m
60 lines (53 loc) · 1.86 KB
/
FirestackErrors.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// FirebaseErrors.m
// Firestack
//
// Created by Ari Lerner on 8/23/16.
// Copyright © 2016 Facebook. All rights reserved.
//
#import "FirestackErrors.h"
@implementation FirestackErrors
RCT_EXPORT_MODULE(FirestackErrors);
+ (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",
[NSString stringWithFormat:@"%d", [error code]], @"code",
[error localizedDescription], @"message",
[[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