Skip to content

Commit f07879f

Browse files
Log more when unknown error returned on iOS (#1606)
It is useful to know more details in further investigation in what circumstances unknown error has been returned like exact status code, background or foreground, etc Relates-To: OCMAM-494 Signed-off-by: Rustam Gamidov <[email protected]>
1 parent 4229277 commit f07879f

File tree

3 files changed

+55
-8
lines changed

3 files changed

+55
-8
lines changed

olp-cpp-sdk-core/src/http/ios/OLPHttpClient.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2023 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,8 @@
2121

2222
#import <Foundation/Foundation.h>
2323

24+
#include <string>
25+
2426
#include "olp/core/http/NetworkTypes.h"
2527

2628
@class OLPHttpTask;
@@ -54,6 +56,9 @@ class NetworkProxySettings;
5456
/// Cancel the task with corresponding request id
5557
- (void)cancelTaskWithId:(olp::http::RequestId)identifier;
5658

59+
/// Get information related to the task with corresponding request id
60+
- (std::string)getInfoForTaskWithId:(olp::http::RequestId)identifier;
61+
5762
/// Finish all tasks in progress and invalidate all URL sessions
5863
- (void)cleanup;
5964

olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -22,6 +22,8 @@
2222
#import <CommonCrypto/CommonDigest.h>
2323
#import <Security/Security.h>
2424

25+
#include <sstream>
26+
2527
#include "context/ContextInternal.h"
2628
#include "olp/core/context/EnterBackgroundSubscriber.h"
2729
#include "olp/core/http/Network.h"
@@ -34,7 +36,7 @@
3436
constexpr auto kMaximumConnectionPerHost = 32;
3537

3638
using SessionId = std::uint64_t;
37-
static SessionId sessionIdCounter_ = std::numeric_limits<SessionId>::min() + 1;
39+
static SessionId sessionIdCounter_ = std::time(nullptr);
3840

3941
class EnterBackgroundSubscriberImpl
4042
: public olp::context::EnterBackgroundSubscriber {
@@ -280,6 +282,36 @@ - (void)removeTaskWithId:(olp::http::RequestId)identifier {
280282
}
281283
}
282284

285+
- (std::string)getInfoForTaskWithId:(olp::http::RequestId)identifier {
286+
@synchronized(_tasks) {
287+
OLPHttpTask* task = _tasks[@(identifier)];
288+
std::stringstream out;
289+
290+
NSNumber* requestId = @(identifier);
291+
NSURLSession* session = self.urlSessions[requestId];
292+
293+
if (!task.dataTask) {
294+
out << "no http task in _tasks for request_id=" << identifier;
295+
return out.str();
296+
}
297+
298+
const auto get_session_config_id = [&]() {
299+
if (session && session.configuration &&
300+
session.configuration.identifier) {
301+
return [session.configuration.identifier UTF8String];
302+
}
303+
return "<not set>";
304+
};
305+
306+
out << "request_id=" << identifier << ", httpTask=" << (__bridge void*)task
307+
<< ", backgroundMode=" << task.backgroundMode
308+
<< ", dataTask=" << (__bridge void*)task.dataTask
309+
<< ", session=" << (__bridge void*)session
310+
<< ", session_config_id=" << get_session_config_id();
311+
return out.str();
312+
}
313+
}
314+
283315
#pragma mark - NSURLSessionDataDelegate
284316

285317
- (void)URLSession:(NSURLSession*)session

olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (C) 2019-2024 HERE Europe B.V.
2+
* Copyright (C) 2019-2025 HERE Europe B.V.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -159,9 +159,8 @@
159159
task = [http_client_ createTaskWithProxy:proxy_settings andId:request_id];
160160
}
161161
if (!task) {
162-
OLP_SDK_LOG_WARNING_F(kLogTag,
163-
"Send failed - can't create task for url=%s",
164-
request.GetUrl().c_str());
162+
OLP_SDK_LOG_ERROR_F(kLogTag, "Send failed - can't create task for url=%s",
163+
request.GetUrl().c_str());
165164
return SendOutcome(ErrorCode::UNKNOWN_ERROR);
166165
}
167166

@@ -317,9 +316,20 @@
317316
if (error && !cancelled) {
318317
error_str = status < 0
319318
? std::string(error.localizedDescription.UTF8String)
320-
: "Failure";
319+
: "Failure, error.code = " + std::to_string(status);
321320
status =
322321
static_cast<int>(ConvertNSURLErrorToNetworkErrorCode(error.code));
322+
323+
if (status == static_cast<int>(ErrorCode::UNKNOWN_ERROR)) {
324+
std::string task_info =
325+
[http_client_ getInfoForTaskWithId:strong_task.requestId];
326+
327+
OLP_SDK_LOG_ERROR_F(kLogTag,
328+
"Task returned unknown error; error_str=%s, "
329+
"task_info: %s, url=%s",
330+
error_str.c_str(), task_info.c_str(),
331+
request.GetUrl().c_str());
332+
}
323333
} else {
324334
status = cancelled ? static_cast<int>(ErrorCode::CANCELLED_ERROR)
325335
: response_data.status;

0 commit comments

Comments
 (0)