Skip to content
This repository was archived by the owner on May 20, 2025. It is now read-only.

Commit ba24d9a

Browse files
committed
Refactoring error creation
1 parent 2740870 commit ba24d9a

File tree

4 files changed

+370
-357
lines changed

4 files changed

+370
-357
lines changed

ios/CodePush/CodePush.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ failCallback:(void (^)(NSError *err))failCallback;
6767

6868
@end
6969

70+
@interface CodePushErrorUtils : NSObject
71+
72+
+ (NSError *)errorWithMessage:(NSString *)errorMessage;
73+
+ (BOOL)isCodePushError:(NSError *)error;
74+
75+
@end
76+
7077
@interface CodePushPackage : NSObject
7178

7279
+ (void)downloadPackage:(NSDictionary *)updatePackage
@@ -90,7 +97,6 @@ failCallback:(void (^)(NSError *err))failCallback;
9097
removePendingUpdate:(BOOL)removePendingUpdate
9198
error:(NSError **)error;
9299

93-
+ (BOOL)isCodePushError:(NSError *)err;
94100
+ (void)rollbackPackage;
95101

96102
// The below methods are only used during tests.

ios/CodePush/CodePush.m

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,7 @@ + (void)ensureBinaryBundleExists
221221
errorMessage = [NSString stringWithFormat:@"The specified JS bundle file wasn't found within the app's binary. Is \"%@\" the correct file name?", [bundleResourceName stringByAppendingPathExtension:bundleResourceExtension]];
222222
#endif
223223

224-
RCTFatal([NSError errorWithDomain:@"CodePushError" code:-1
225-
userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(errorMessage, nil) }]);
224+
RCTFatal([CodePushErrorUtils errorWithMessage:errorMessage]);
226225
}
227226
}
228227

ios/CodePush/CodePushErrorUtils.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#import "CodePush.h"
2+
3+
@implementation CodePushErrorUtils
4+
5+
static NSString *const CodePushErrorDomain = @"CodePushError";
6+
static const int CodePushErrorCode = -1;
7+
8+
+ (NSError *)errorWithMessage:(NSString *)errorMessage
9+
{
10+
return [NSError errorWithDomain:CodePushErrorDomain
11+
code:CodePushErrorCode
12+
userInfo:@{ NSLocalizedDescriptionKey: NSLocalizedString(errorMessage, nil) }];
13+
}
14+
15+
+ (BOOL)isCodePushError:(NSError *)err
16+
{
17+
return err != nil && [CodePushErrorDomain isEqualToString:err.domain];
18+
}
19+
20+
@end

0 commit comments

Comments
 (0)