From f50a4fa5e8332ef986db436197291e36ecd48482 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henri=20Ma=CC=88gi?= Date: Mon, 13 Jul 2020 18:05:14 +0300 Subject: [PATCH 1/2] Adds response data to HTTPFailureReponse case. It allows to show the error response, if supplied, to the end user. It helps in debugging. The parsing of the response is left to the app that implements the SDK, since the responses can differ from one service to another. --- Sources/DP3TSDK/DP3TError.swift | 4 ++-- Sources/DP3TSDK/Networking/ExposeeServiceClient.swift | 10 +++++----- Tests/DP3TSDKTests/KnownCasesSynchronizerTests.swift | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Sources/DP3TSDK/DP3TError.swift b/Sources/DP3TSDK/DP3TError.swift index 6b724ece..cfd44bf8 100644 --- a/Sources/DP3TSDK/DP3TError.swift +++ b/Sources/DP3TSDK/DP3TError.swift @@ -45,7 +45,7 @@ public enum DP3TNetworkingError: Error { /// The response is not an HTTP response case notHTTPResponse /// An unexpected HTTP error state was returned - case HTTPFailureResponse(status: Int) + case HTTPFailureResponse(status: Int, data: Data?) /// Response body was not expected to be empty case noDataReturned /// The returned body could not be parsed. The data might be in the wrong format or corrupted @@ -77,7 +77,7 @@ public enum DP3TNetworkingError: Error { return 600 case .timeInconsistency: return 700 - case let .HTTPFailureResponse(status: status): + case let .HTTPFailureResponse(status: status, data: _): // Combines the HTTP Status error with the error return 8000 + status case .jwtSignatureError(code: let code, debugDescription: _): diff --git a/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift b/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift index 174c033d..4585fb0d 100644 --- a/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift +++ b/Sources/DP3TSDK/Networking/ExposeeServiceClient.swift @@ -146,7 +146,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol { completion(.success(.init(data: nil, publishedUntil: publishedUntil))) return default: - completion(.failure(.HTTPFailureResponse(status: httpStatus))) + completion(.failure(.HTTPFailureResponse(status: httpStatus, data: data))) return } @@ -200,7 +200,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol { } request.httpBody = payload - let task = urlSession.dataTask(with: request, completionHandler: { _, response, error in + let task = urlSession.dataTask(with: request, completionHandler: { data, response, error in guard error == nil else { completion(.failure(.networkSessionError(error: error!))) return @@ -212,7 +212,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol { let statusCode = httpResponse.statusCode guard statusCode == 200 else { - completion(.failure(.HTTPFailureResponse(status: statusCode))) + completion(.failure(.HTTPFailureResponse(status: statusCode, data: data))) return } @@ -246,7 +246,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol { } request.httpBody = payload - let task = urlSession.dataTask(with: request, completionHandler: { _, response, error in + let task = urlSession.dataTask(with: request, completionHandler: { data, response, error in guard error == nil else { completion(.failure(.networkSessionError(error: error!))) return @@ -258,7 +258,7 @@ class ExposeeServiceClient: ExposeeServiceClientProtocol { let statusCode = httpResponse.statusCode guard statusCode == 200 else { - completion(.failure(.HTTPFailureResponse(status: statusCode))) + completion(.failure(.HTTPFailureResponse(status: statusCode, data: data))) return } diff --git a/Tests/DP3TSDKTests/KnownCasesSynchronizerTests.swift b/Tests/DP3TSDKTests/KnownCasesSynchronizerTests.swift index cc2247a0..ca0385ab 100644 --- a/Tests/DP3TSDKTests/KnownCasesSynchronizerTests.swift +++ b/Tests/DP3TSDKTests/KnownCasesSynchronizerTests.swift @@ -292,7 +292,7 @@ final class KnownCasesSynchronizerTests: XCTestCase { let matcher = MockMatcher() let service = MockService() let defaults = MockDefaults() - service.error = .HTTPFailureResponse(status: 400) + service.error = .HTTPFailureResponse(status: 400, data: nil) service.errorAfter = 5 let sync = KnownCasesSynchronizer(matcher: matcher, service: service, From b11f65fddfbafb103c2bcb3170d19c6e46b30955 Mon Sep 17 00:00:00 2001 From: Stefan Mitterrutzner Date: Thu, 13 Aug 2020 12:12:36 +0200 Subject: [PATCH 2/2] updates version --- CHANGELOG.md | 3 +++ DP3TSDK.podspec | 2 +- README.md | 2 +- Sources/DP3TSDK/DP3TTracing.swift | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 34136b27..841d39bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog for DP3T-SDK iOS +## Version 1.1.1 (13.08.2020) +- DP3TNetworkingError.HTTPFailureResponse includes raw data + ## Version 1.1.0 (17.07.2020) - adds background refresh task to improve background time - retrieves keys in background on iOS > 13.6 diff --git a/DP3TSDK.podspec b/DP3TSDK.podspec index dc9b15d3..79927fc7 100644 --- a/DP3TSDK.podspec +++ b/DP3TSDK.podspec @@ -2,7 +2,7 @@ Pod::Spec.new do |spec| spec.name = "DP3TSDK" - spec.version = ENV['LIB_VERSION'] || '1.1.0' + spec.version = ENV['LIB_VERSION'] || '1.1.1' spec.summary = "Open protocol for COVID-19 proximity tracing using Bluetooth Low Energy on mobile devices" spec.description = <<-DESC diff --git a/README.md b/README.md index c071870c..7dae2482 100644 --- a/README.md +++ b/README.md @@ -74,7 +74,7 @@ DP3T-SDK is available through [Cocoapods](https://cocoapods.org/) ```ruby - pod 'DP3TSDK', => '1.1.0' + pod 'DP3TSDK', => '1.1.1' ``` diff --git a/Sources/DP3TSDK/DP3TTracing.swift b/Sources/DP3TSDK/DP3TTracing.swift index 7574d44a..63c5be78 100644 --- a/Sources/DP3TSDK/DP3TTracing.swift +++ b/Sources/DP3TSDK/DP3TTracing.swift @@ -28,7 +28,7 @@ private var instance: DP3TSDK! /// DP3TTracing public enum DP3TTracing { /// The current version of the SDK - public static let frameworkVersion: String = "1.1.0" + public static let frameworkVersion: String = "1.1.1" /// sets global parameter values which are used throughout the sdk public static var parameters: DP3TParameters {