forked from birdofpreyru/react-native-fs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRNFSException.mm
80 lines (67 loc) · 1.78 KB
/
RNFSException.mm
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#import "RNFSException.h"
static NSString * const ERROR_DOMAIN = @"RNFS";
@implementation RNFSException;
- (id) initWithName:(NSString*)name details:(NSString*)details
{
self = [super initWithName:name reason:details userInfo:nil];
return self;
}
/**
* Creates a new NSError object based on this RNFSException
*/
- (NSError*) error
{
return [NSError
errorWithDomain: ERROR_DOMAIN
code: self.code
userInfo: self.userInfo
];
}
- (RNFSException*) log
{
NSLog(@"%@: %@", self.name, self.reason);
return self;
}
- (void) reject: (RCTPromiseRejectBlock)reject
{
reject(self.name, self.reason, [self error]);
}
- (void) reject: (RCTPromiseRejectBlock)reject details: (NSString*) details
{
NSString *reason = self.reason;
if (details != nil) reason = [reason stringByAppendingString:details];
reject(self.name, reason, [self error]);
}
+ (RNFSException*) fromError:(NSError *)error
{
NSString *name = [NSString stringWithFormat:@"%@:%ld",
error.domain, error.code];
return [[RNFSException alloc]
initWithName:name
reason:error.localizedDescription
userInfo:error.userInfo];
}
+ (RNFSException*) fromException:(NSException *)exception
{
return [[RNFSException alloc]
initWithName: exception.name
reason: exception.reason
userInfo: exception.userInfo];
}
+ (RNFSException*) name: (NSString*)name
{
return [[RNFSException alloc] initWithName:name details:nil];
}
+ (RNFSException*) name: (NSString*)name details:(NSString*)details
{
return [[RNFSException alloc] initWithName:name details:details];
}
+ (RNFSException*) NOT_IMPLEMENTED
{
return [
[RNFSException alloc]
initWithName:@"NOT_IMPLEMENTED"
details:@"This method is not implemented for iOS"
];
}
@end;