diff --git a/Sources/BranchSDK/BNCServerInterface.m b/Sources/BranchSDK/BNCServerInterface.m index 37cfcfd1d..9cc4fd789 100644 --- a/Sources/BranchSDK/BNCServerInterface.m +++ b/Sources/BranchSDK/BNCServerInterface.m @@ -148,7 +148,24 @@ - (void)genericHTTPRequest:(NSURLRequest *)request retryNumber:(NSInteger)retryN 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]; + // If a network request is successful, the `data` field will be populated with the error response from the service + // We have to create an NSError object here to pass down to callback. + + if(serverResponse.data && serverResponse.data[@"error"] != nil){ + id errorJson = serverResponse.data[@"error"]; + + if(errorJson[@"message"] != nil){ + NSString *errorString = errorJson[@"message"]; + NSDictionary *userInfo = @{ + NSLocalizedDescriptionKey: errorString, + }; + underlyingError = [NSError errorWithDomain:[NSError bncErrorDomain] + code:[(errorJson[@"code"]) integerValue] + userInfo:userInfo]; + } + } + + [[BranchLogger shared] logError: [NSString stringWithFormat:@"Giving up on request with HTTP status code %ld", (long)status] error:underlyingError]; } }