Skip to content

Commit

Permalink
Updated ad blocker log warnings to errors (#1417)
Browse files Browse the repository at this point in the history
* Updated warnings to errors

* Created new Branch errors
  • Loading branch information
nsingh-branch authored Jul 26, 2024
1 parent 806a138 commit b8e6384
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
6 changes: 4 additions & 2 deletions Sources/BranchSDK/BNCServerInterface.m
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,11 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN
} else {
if (status != 200) {
if ([NSError branchDNSBlockingError:underlyingError]) {
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Possible DNS Ad Blocker. Giving up on request with HTTP status code %ld", (long)status] error:underlyingError];
NSError *error = [NSError branchErrorWithCode:BNCDNSAdBlockerError];
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Possible DNS Ad Blocker. Giving up on request with HTTP status code %ld. Underlying error: %@", (long)status, underlyingError] error:error];
} else if ([NSError branchVPNBlockingError:underlyingError]) {
[[BranchLogger shared] logWarning:[NSString stringWithFormat:@"Possible VPN Ad Blocker. Giving up on request with HTTP status code %ld", (long)status] error:underlyingError];
NSError *error = [NSError branchErrorWithCode:BNCVPNAdBlockerError];
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Possible VPN Ad Blocker. Giving up on request with HTTP status code %ld. Underlying error: %@", (long)status, underlyingError] error:error];
} else {
[[BranchLogger shared] logWarning: [NSString stringWithFormat:@"Giving up on request with HTTP status code %ld", (long)status] error:underlyingError];
}
Expand Down
8 changes: 5 additions & 3 deletions Sources/BranchSDK/BNCURLFilter.m
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ - (BOOL)foundUpdatedURLList:(id<BNCNetworkOperationProtocol>)operation {
if (statusCode == 404) {
[[BranchLogger shared] logDebug:@"No update for URL ignore list found." error:nil];
return NO;
} else if (statusCode != 200 || error != nil || jsonString == nil) {
} else if (statusCode != 200 || error != nil || jsonString == nil) {
if ([NSError branchDNSBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible DNS Ad Blocker" error:error];
NSError *dnsError = [NSError branchErrorWithCode:BNCDNSAdBlockerError];
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Possible DNS Ad Blocker. Giving up on request with HTTP status code %ld. Underlying error: %@", (long)statusCode, error] error:dnsError];
} else if ([NSError branchVPNBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible VPN Ad Blocker" error:error];
NSError *vpnError = [NSError branchErrorWithCode:BNCVPNAdBlockerError];
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Possible VPN Ad Blocker. Giving up on request with HTTP status code %ld. Underlying error: %@", (long)statusCode, error] error:vpnError];
} else {
[[BranchLogger shared] logWarning:@"Failed to update URL ignore list" error:operation.error];
}
Expand Down
6 changes: 4 additions & 2 deletions Sources/BranchSDK/BranchQRCode.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,11 @@ - (void)callQRCodeAPI:(nullable NSDictionary *)params

if (error) {
if ([NSError branchDNSBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible DNS Ad Blocker" error:error];
NSError *dnsError = [NSError branchErrorWithCode:BNCDNSAdBlockerError];
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Possible DNS Ad Blocker. Giving up on QR code request. Underlying error: %@", error] error:dnsError];
} else if ([NSError branchVPNBlockingError:error]) {
[[BranchLogger shared] logWarning:@"Possible VPN Ad Blocker" error:error];
NSError *vpnError = [NSError branchErrorWithCode:BNCVPNAdBlockerError];
[[BranchLogger shared] logError:[NSString stringWithFormat:@"Possible VPN Ad Blocker. Giving up on QR code request. Underlying error: %@", error] error:vpnError];
} else {
[[BranchLogger shared] logError:@"QR Code request failed" error:error];
completion(nil, error);
Expand Down
2 changes: 2 additions & 0 deletions Sources/BranchSDK/NSError+Branch.m
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ + (NSString *)messageForCode:(BNCErrorCode)code {
[messages setObject:@"The Spotlight identifier is required to remove indexing from spotlight." forKey:@(BNCSpotlightIdentifierError)];
[messages setObject:@"Spotlight cannot remove publicly indexed content." forKey:@(BNCSpotlightPublicIndexError)];
[messages setObject:@"User tracking is disabled and the request is not allowed" forKey:@(BNCTrackingDisabledError)];
[messages setObject:@"Possible DNS Ad Blocker. Giving up on request." forKey:@(BNCDNSAdBlockerError)];
[messages setObject:@"Possible VPN Ad Blocker. Giving up on request." forKey:@(BNCVPNAdBlockerError)];
});

NSString *errorMessage = [messages objectForKey:@(code)];
Expand Down
2 changes: 2 additions & 0 deletions Sources/BranchSDK/Private/NSError+Branch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ typedef NS_ENUM(NSInteger, BNCErrorCode) {
BNCSpotlightPublicIndexError = 1014,
BNCTrackingDisabledError = 1015,
BNCGeneralError = 1016, // General Branch SDK Error
BNCDNSAdBlockerError = 1017,
BNCVPNAdBlockerError = 1018,
BNCHighestError
};

Expand Down

0 comments on commit b8e6384

Please sign in to comment.