Skip to content

Commit 6e8443e

Browse files
committed
Return empty data on error in multipart datatask.
1 parent 1408e06 commit 6e8443e

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

Cartfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
github "NeoTeo/SwiftMultiaddr"
2+
#git "file:///Users/teo/source/Apple/macOS/Libraries/SwiftMultiaddr" "test"

SwiftIpfsApi.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@
402402
GCC_WARN_UNUSED_VARIABLE = YES;
403403
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
404404
LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks";
405-
MACOSX_DEPLOYMENT_TARGET = 10.11;
405+
MACOSX_DEPLOYMENT_TARGET = 10.13;
406406
MTL_ENABLE_DEBUG_INFO = YES;
407407
ONLY_ACTIVE_ARCH = YES;
408408
SDKROOT = macosx;
@@ -471,7 +471,7 @@
471471
GCC_WARN_UNUSED_VARIABLE = YES;
472472
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
473473
LD_RUNPATH_SEARCH_PATHS = "@loader_path/Frameworks";
474-
MACOSX_DEPLOYMENT_TARGET = 10.11;
474+
MACOSX_DEPLOYMENT_TARGET = 10.13;
475475
MTL_ENABLE_DEBUG_INFO = NO;
476476
SDKROOT = macosx;
477477
SUPPORTED_PLATFORMS = "macosx iphonesimulator iphoneos";

SwiftIpfsApi/Multipart.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,14 @@ extension Multipart {
154154
let task = URLSession.shared.dataTask(with: (multipart.request as URLRequest)) {
155155
(data: Data?, response: URLResponse?, error: Error?) -> Void in
156156

157-
guard error == nil && data != nil else {
158-
print("Error in dataTaskWithRequest: \(String(describing: error))")//throw HttpIoError.TransmissionError("fail: \(error)")
157+
// FIXME: use Swift 5 Result type rather than passing nil data.
158+
if error != nil || data == nil {
159+
print("Error in dataTaskWithRequest: \(String(describing: error))")
160+
let emptyData = Data()
161+
completionHandler(emptyData)
159162
return
160163
}
161-
164+
162165
completionHandler(data!)
163166

164167
}

SwiftIpfsApiTests/SwiftIpfsApiTests.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ class SwiftIpfsApiTests: XCTestCase {
6060
try api.refs.local() { (localRefs: [Multihash]) in
6161

6262
for mh in localRefs {
63-
print(b58String(mh))
63+
// Bad assumption that the string is necessarily in base 58.
64+
// Check first.
65+
print("multihash string :\(mh.string())")
66+
// print(b58String(mh))
6467
}
6568

6669
expectation.fulfill()

0 commit comments

Comments
 (0)