diff --git a/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.h b/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.h index 58992b387..59ec12bfd 100644 --- a/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.h +++ b/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2023 HERE Europe B.V. + * Copyright (C) 2019-2025 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,8 @@ #import +#include + #include "olp/core/http/NetworkTypes.h" @class OLPHttpTask; @@ -54,6 +56,9 @@ class NetworkProxySettings; /// Cancel the task with corresponding request id - (void)cancelTaskWithId:(olp::http::RequestId)identifier; +/// Get information related to the task with corresponding request id +- (std::string)getInfoForTaskWithId:(olp::http::RequestId)identifier; + /// Finish all tasks in progress and invalidate all URL sessions - (void)cleanup; diff --git a/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm b/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm index 83dc7949d..0ad49d5cd 100644 --- a/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm +++ b/olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 HERE Europe B.V. + * Copyright (C) 2019-2025 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ #import #import +#include + #include "context/ContextInternal.h" #include "olp/core/context/EnterBackgroundSubscriber.h" #include "olp/core/http/Network.h" @@ -34,7 +36,7 @@ constexpr auto kMaximumConnectionPerHost = 32; using SessionId = std::uint64_t; -static SessionId sessionIdCounter_ = std::numeric_limits::min() + 1; +static SessionId sessionIdCounter_ = std::time(nullptr); class EnterBackgroundSubscriberImpl : public olp::context::EnterBackgroundSubscriber { @@ -280,6 +282,36 @@ - (void)removeTaskWithId:(olp::http::RequestId)identifier { } } +- (std::string)getInfoForTaskWithId:(olp::http::RequestId)identifier { + @synchronized(_tasks) { + OLPHttpTask* task = _tasks[@(identifier)]; + std::stringstream out; + + NSNumber* requestId = @(identifier); + NSURLSession* session = self.urlSessions[requestId]; + + if (!task.dataTask) { + out << "no http task in _tasks for request_id=" << identifier; + return out.str(); + } + + const auto get_session_config_id = [&]() { + if (session && session.configuration && + session.configuration.identifier) { + return [session.configuration.identifier UTF8String]; + } + return ""; + }; + + out << "request_id=" << identifier << ", httpTask=" << (__bridge void*)task + << ", backgroundMode=" << task.backgroundMode + << ", dataTask=" << (__bridge void*)task.dataTask + << ", session=" << (__bridge void*)session + << ", session_config_id=" << get_session_config_id(); + return out.str(); + } +} + #pragma mark - NSURLSessionDataDelegate - (void)URLSession:(NSURLSession*)session diff --git a/olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm b/olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm index ce709109e..6c4fec670 100644 --- a/olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm +++ b/olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019-2024 HERE Europe B.V. + * Copyright (C) 2019-2025 HERE Europe B.V. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -159,9 +159,8 @@ task = [http_client_ createTaskWithProxy:proxy_settings andId:request_id]; } if (!task) { - OLP_SDK_LOG_WARNING_F(kLogTag, - "Send failed - can't create task for url=%s", - request.GetUrl().c_str()); + OLP_SDK_LOG_ERROR_F(kLogTag, "Send failed - can't create task for url=%s", + request.GetUrl().c_str()); return SendOutcome(ErrorCode::UNKNOWN_ERROR); } @@ -317,9 +316,20 @@ if (error && !cancelled) { error_str = status < 0 ? std::string(error.localizedDescription.UTF8String) - : "Failure"; + : "Failure, error.code = " + std::to_string(status); status = static_cast(ConvertNSURLErrorToNetworkErrorCode(error.code)); + + if (status == static_cast(ErrorCode::UNKNOWN_ERROR)) { + std::string task_info = + [http_client_ getInfoForTaskWithId:strong_task.requestId]; + + OLP_SDK_LOG_ERROR_F(kLogTag, + "Task returned unknown error; error_str=%s, " + "task_info: %s, url=%s", + error_str.c_str(), task_info.c_str(), + request.GetUrl().c_str()); + } } else { status = cancelled ? static_cast(ErrorCode::CANCELLED_ERROR) : response_data.status;