diff --git a/Sources/Qonversion/Public/QONErrors.h b/Sources/Qonversion/Public/QONErrors.h index e477ca2d..465663a5 100644 --- a/Sources/Qonversion/Public/QONErrors.h +++ b/Sources/Qonversion/Public/QONErrors.h @@ -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); @@ -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; diff --git a/Sources/Qonversion/Public/QONErrors.m b/Sources/Qonversion/Public/QONErrors.m index eebcb36f..2de08ebc 100644 --- a/Sources/Qonversion/Public/QONErrors.m +++ b/Sources/Qonversion/Public/QONErrors.m @@ -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]; } diff --git a/Sources/Qonversion/Qonversion/Services/QONRemoteConfigService/QONRemoteConfigService.m b/Sources/Qonversion/Qonversion/Services/QONRemoteConfigService/QONRemoteConfigService.m index 5f72739d..57593299 100644 --- a/Sources/Qonversion/Qonversion/Services/QONRemoteConfigService/QONRemoteConfigService.m +++ b/Sources/Qonversion/Qonversion/Services/QONRemoteConfigService/QONRemoteConfigService.m @@ -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 @@ -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); }]; }