From 3b68bfb222b1aa44e21356d2bf92471a4fd2b00a Mon Sep 17 00:00:00 2001 From: Surik Date: Fri, 11 Oct 2024 16:57:22 +0400 Subject: [PATCH] Added error for empty offerings and empty error case --- Sources/Qonversion/Public/QONErrors.h | 6 +++++- Sources/Qonversion/Public/QONErrors.m | 7 +++++++ .../Main/QNProductCenterManager/QNProductCenterManager.m | 4 ++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Sources/Qonversion/Public/QONErrors.h b/Sources/Qonversion/Public/QONErrors.h index 5d2ce103..820e79c6 100644 --- a/Sources/Qonversion/Public/QONErrors.h +++ b/Sources/Qonversion/Public/QONErrors.h @@ -67,7 +67,10 @@ typedef NS_ERROR_ENUM(QONErrorDomain, QONError) { QONErrorStorePaymentDeferred = 18, // No remote configuration for the current user - QONErrorRemoteConfigurationNotAvailable = 19 + QONErrorRemoteConfigurationNotAvailable = 19, + + // No offerings for the current user + QONErrorOfferingsNotAvailable = 20, } NS_SWIFT_NAME(Qonversion.Error); @@ -131,6 +134,7 @@ typedef NS_ERROR_ENUM(QONErrorDomain, QONAPIError) { + (NSError *)errorFromURLDomainError:(NSError *)error; + (NSError *)errorFromTransactionError:(NSError *)error; + (NSError *)deferredTransactionError; ++ (NSError *)emptyOfferingsError; @end diff --git a/Sources/Qonversion/Public/QONErrors.m b/Sources/Qonversion/Public/QONErrors.m index 8349682b..4588f8cf 100644 --- a/Sources/Qonversion/Public/QONErrors.m +++ b/Sources/Qonversion/Public/QONErrors.m @@ -58,6 +58,13 @@ + (NSError *)deferredTransactionError { return [self errorWithQonversionErrorCode:QONErrorStorePaymentDeferred userInfo:[userInfo copy]]; } ++ (NSError *)emptyOfferingsError { + NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; + userInfo[NSLocalizedDescriptionKey] = @"Offerings are not available"; + + return [self errorWithQonversionErrorCode:QONErrorOfferingsNotAvailable userInfo:[userInfo copy]]; +} + + (NSError *)errorFromTransactionError:(NSError *)error { QONError errorCode = QONErrorUnknown; NSMutableDictionary *userInfo = [[NSMutableDictionary alloc] init]; diff --git a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m index cfba7f8a..0a443f63 100644 --- a/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m +++ b/Sources/Qonversion/Qonversion/Main/QNProductCenterManager/QNProductCenterManager.m @@ -616,6 +616,10 @@ - (void)executeOfferingsBlocksWithError:(NSError * _Nullable)error { QONOfferings *offerings = [self enrichOfferingsWithStoreProducts]; resultError = offerings ? nil : resultError; + if (!offerings && !resultError) { + resultError = [QONErrors emptyOfferingsError]; + } + for (QONOfferingsCompletionHandler block in blocks) { run_block_on_main(block, offerings, resultError); }