Skip to content

Log more when unknown error returned on iOS #1606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion olp-cpp-sdk-core/src/http/ios/OLPHttpClient.h
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,6 +21,8 @@

#import <Foundation/Foundation.h>

#include <string>

#include "olp/core/http/NetworkTypes.h"

@class OLPHttpTask;
Expand Down Expand Up @@ -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;

Expand Down
36 changes: 34 additions & 2 deletions olp-cpp-sdk-core/src/http/ios/OLPHttpClient.mm
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -22,6 +22,8 @@
#import <CommonCrypto/CommonDigest.h>
#import <Security/Security.h>

#include <sstream>

#include "context/ContextInternal.h"
#include "olp/core/context/EnterBackgroundSubscriber.h"
#include "olp/core/http/Network.h"
Expand All @@ -34,7 +36,7 @@
constexpr auto kMaximumConnectionPerHost = 32;

using SessionId = std::uint64_t;
static SessionId sessionIdCounter_ = std::numeric_limits<SessionId>::min() + 1;
static SessionId sessionIdCounter_ = std::time(nullptr);

class EnterBackgroundSubscriberImpl
: public olp::context::EnterBackgroundSubscriber {
Expand Down Expand Up @@ -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 "<not set>";
};

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
Expand Down
20 changes: 15 additions & 5 deletions olp-cpp-sdk-core/src/http/ios/OLPNetworkIOS.mm
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<int>(ConvertNSURLErrorToNetworkErrorCode(error.code));

if (status == static_cast<int>(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<int>(ErrorCode::CANCELLED_ERROR)
: response_data.status;
Expand Down
Loading