Skip to content

Commit 80a790f

Browse files
committed
add error handler to datafile manager class
1 parent f227e5a commit 80a790f

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@
1616

1717
#import <Foundation/Foundation.h>
1818
#import "OPTLYDatafileManagerBuilder.h"
19-
#import <OptimizelySDKShared/OPTLYHTTPRequestManager.h>
19+
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
2020
#import <OptimizelySDKCore/OPTLYLogger.h>
21+
#import <OptimizelySDKShared/OPTLYHTTPRequestManager.h>
22+
2123

22-
@protocol OPTLYLogger;
24+
@protocol OPTLYErrorHandler, OPTLYLogger;
2325

2426
@protocol OPTLYDatafileManager <NSObject>
2527

@@ -39,6 +41,8 @@
3941
@property (nonatomic, readonly) NSTimeInterval datafileFetchInterval;
4042
/// The project ID of the datafile this datafile manager will monitor
4143
@property (nonatomic, readonly, strong, nonnull) NSString *projectId;
44+
/// The error handler to be used for the manager, client, and all subcomponents
45+
@property (nonatomic, readwrite, strong, nullable) id<OPTLYErrorHandler> errorHandler;
4246
/// A logger for the OPTLYDatafileManager to log messages.
4347
@property (nonatomic, readonly, strong, nonnull) id<OPTLYLogger> logger;
4448

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManager.m

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ - (instancetype)initWithBuilder:(OPTLYDatafileManagerBuilder *)builder {
4141
_datafileFetchInterval = kDefaultDatafileFetchInterval;
4242
_datafileFetchInterval = builder.datafileFetchInterval;
4343
_projectId = builder.projectId;
44+
_errorHandler = builder.errorHandler;
4445
_logger = builder.logger;
4546
_networkService = [[OPTLYNetworkService alloc] init];
4647
_dataStore = [OPTLYDataStore new];
@@ -64,7 +65,7 @@ - (void)downloadDatafile:(NSString *)projectId completionHandler:(OPTLYHTTPReque
6465
[self.networkService downloadProjectConfig:self.projectId
6566
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
6667
if (error != nil) {
67-
// TODO: Josh W. handle errors
68+
[self.errorHandler handleError:error];
6869
}
6970
else if ([(NSHTTPURLResponse *)response statusCode] == 200) { // got datafile OK
7071
[self saveDatafile:data];

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManagerBuilder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
#import <Foundation/Foundation.h>
1818

1919
@class OPTLYDatafileManagerBuilder;
20-
@protocol OPTLYLogger;
20+
@protocol OPTLYErrorHandler, OPTLYLogger;
2121

2222
/// This is a block that takes the biulder values
2323
typedef void (^OPTLYDatafileManagerBuilderBlock)(OPTLYDatafileManagerBuilder * _Nullable builder);
@@ -30,10 +30,11 @@ typedef void (^OPTLYDatafileManagerBuilderBlock)(OPTLYDatafileManagerBuilder * _
3030
@property (nonatomic, readwrite) NSTimeInterval datafileFetchInterval;
3131
/// The projectID of the project we want to get the datafile for.
3232
@property (nonatomic, readwrite, strong, nonnull) NSString *projectId;
33+
/// The error handler to be used for the manager, client, and all subcomponents
34+
@property (nonatomic, readwrite, strong, nullable) id<OPTLYErrorHandler> errorHandler;
3335
/// A logger to inject for purposes of error logging. If none is passed in, a default logger with log level `All` will be created.
3436
@property (nonatomic, readwrite, strong, nonnull) id<OPTLYLogger> logger;
3537

36-
3738
/// Create an Optimizely Datafile Manager Builder object.
3839
+ (nullable instancetype)builderWithBlock:(nonnull OPTLYDatafileManagerBuilderBlock)block;
3940

OptimizelySDKDatafileManager/OptimizelySDKDatafileManager/OPTLYDatafileManagerBuilder.m

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
***************************************************************************/
1616

1717
#import "OPTLYDatafileManagerBuilder.h"
18+
#import <OptimizelySDKCore/OPTLYErrorHandler.h>
1819
#import <OptimizelySDKCore/OPTLYLogger.h>
1920
#import <OptimizelySDKCore/OPTLYLoggerMessages.h>
2021

@@ -62,4 +63,11 @@ - (NSTimeInterval)datafileFetchInterval {
6263
return _logger;
6364
}
6465

66+
- (id<OPTLYErrorHandler>)errorHandler {
67+
if (!_errorHandler) {
68+
_errorHandler = [[OPTLYErrorHandlerNoOp alloc] init];
69+
}
70+
return _errorHandler;
71+
}
72+
6573
@end

0 commit comments

Comments
 (0)