Skip to content

Commit

Permalink
Updated error handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
suriksarkisyan committed Sep 11, 2023
1 parent ccaee05 commit 6e8bc5e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Sources/Qonversion/Public/QONErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,12 @@ typedef NS_ERROR_ENUM(QONErrorDomain, QONError) {
// Internal error occurred
QONErrorInternalError = 17,

// The paymet was deferred
QONErrorStorePaymentDeferred = 18,

// No remote configuration for the current user
QONErrorRemoteConfigurationNotAvailable,

} NS_SWIFT_NAME(Qonversion.Error);


Expand Down Expand Up @@ -117,6 +121,7 @@ typedef NS_ERROR_ENUM(QONErrorDomain, QONAPIError) {

@interface QONErrors: NSObject

+ (NSError *)errorWithCode:(QONError)errorCode message:(NSString *)message;
+ (NSError *)errorWithCode:(QONAPIError)errorCode;
+ (NSError *)errorWithCode:(QONAPIError)errorCode message:(NSString *)message failureReason:(NSString *)failureReason;
+ (NSError *)errorWithQONErrorCode:(QONError)errorCode;
Expand Down
9 changes: 9 additions & 0 deletions Sources/Qonversion/Public/QONErrors.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ + (NSError *)errorWithCode:(QONAPIError)errorCode message:(NSString *)message fa
return error;
}

+ (NSError *)errorWithCode:(QONError)errorCode message:(NSString *)message {
NSMutableDictionary *info = [NSMutableDictionary new];
info[NSLocalizedDescriptionKey] = NSLocalizedString(message, nil);

NSError *error = [NSError errorWithDomain:keyQONErrorDomain code:errorCode userInfo:[info copy]];

return error;
}

+ (NSError *)errorWithQONErrorCode:(QONError)errorCode {
return [self errorWithQonversionErrorCode:errorCode userInfo:nil];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#import "QONRemoteConfigService.h"
#import "QNAPIClient.h"
#import "QONRemoteConfigMapper.h"
#import "QONRemoteConfig.h"
#import "QONErrors.h"

static NSString *const kNoRemoteConfigurationErrorMessage = @"Remote configuration for the current user not available";

@implementation QONRemoteConfigService

Expand All @@ -33,6 +37,12 @@ - (void)loadRemoteConfig:(QONRemoteConfigCompletionHandler)completion {

QONRemoteConfig *config = [weakSelf.mapper mapRemoteConfig:dict];

if (config.payload.count == 0 && config.source == nil) {
NSError *error = [QONErrors errorWithCode:QONErrorRemoteConfigurationNotAvailable message:kNoRemoteConfigurationErrorMessage];
completion(nil, error);
return;
}

completion(config, error);
}];
}
Expand Down

0 comments on commit 6e8bc5e

Please sign in to comment.