From 3fe2fcac8c691cfdf65dd7e7ed708d00530faf98 Mon Sep 17 00:00:00 2001 From: Caleb Kleveter Date: Mon, 17 Dec 2018 13:43:18 -0600 Subject: [PATCH 1/2] Allow all HTTP status codes in range 200-299 to pass as non-error codes --- Sources/GoogleCloud/Storage/StorageRequest.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/GoogleCloud/Storage/StorageRequest.swift b/Sources/GoogleCloud/Storage/StorageRequest.swift index 44ec3d6..f0aad44 100644 --- a/Sources/GoogleCloud/Storage/StorageRequest.swift +++ b/Sources/GoogleCloud/Storage/StorageRequest.swift @@ -72,7 +72,7 @@ public final class GoogleCloudStorageRequest { headers.forEach { finalHeaders.replaceOrAdd(name: $0.name, value: $0.value) } return httpClient.send(method, headers: finalHeaders, to: "\(path)?\(query)", beforeSend: { $0.http.body = body }).flatMap({ response in - guard response.http.status == .ok else { + guard (200...299).contains(response.http.status.code) else { return try self.responseDecoder.decode(CloudStorageError.self, from: response.http, maxSize: 65_536, on: self.httpClient.container).map { error in throw error }.catchMap { error -> Response in From cbf92919abb92c1b051d38dd40f456580da38d1f Mon Sep 17 00:00:00 2001 From: Caleb Kleveter Date: Mon, 17 Dec 2018 13:43:53 -0600 Subject: [PATCH 2/2] Assign an empty JSON object to response body to properly decode an EmptyResponse object --- Sources/GoogleCloud/Storage/StorageRequest.swift | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Sources/GoogleCloud/Storage/StorageRequest.swift b/Sources/GoogleCloud/Storage/StorageRequest.swift index f0aad44..a836acf 100644 --- a/Sources/GoogleCloud/Storage/StorageRequest.swift +++ b/Sources/GoogleCloud/Storage/StorageRequest.swift @@ -40,6 +40,10 @@ public final class GoogleCloudStorageRequest { func send(method: HTTPMethod, headers: HTTPHeaders = [:], path: String, query: String, body: HTTPBody = HTTPBody()) throws -> Future { return try withToken({ token in return try self._send(method: method, headers: headers, path: path, query: query, body: body, accessToken: token.accessToken).flatMap({ response in + if GCM.self is EmptyResponse.Type && response.http.body.data == Data() { + response.http.body = HTTPBody(staticString: "{}") + } + return try self.responseDecoder.decode(GCM.self, from: response.http, maxSize: 65_536, on: response) }) })