Skip to content

Commit 599a135

Browse files
authored
Merge pull request #14 from vapor-community/empty-response-decoding
Fixed Decoding EmptyResponse Type
2 parents 85567da + cbf9291 commit 599a135

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

Sources/GoogleCloud/Storage/StorageRequest.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public final class GoogleCloudStorageRequest {
4040
func send<GCM: GoogleCloudModel>(method: HTTPMethod, headers: HTTPHeaders = [:], path: String, query: String, body: HTTPBody = HTTPBody()) throws -> Future<GCM> {
4141
return try withToken({ token in
4242
return try self._send(method: method, headers: headers, path: path, query: query, body: body, accessToken: token.accessToken).flatMap({ response in
43+
if GCM.self is EmptyResponse.Type && response.http.body.data == Data() {
44+
response.http.body = HTTPBody(staticString: "{}")
45+
}
46+
4347
return try self.responseDecoder.decode(GCM.self, from: response.http, maxSize: 65_536, on: response)
4448
})
4549
})
@@ -72,7 +76,7 @@ public final class GoogleCloudStorageRequest {
7276
headers.forEach { finalHeaders.replaceOrAdd(name: $0.name, value: $0.value) }
7377

7478
return httpClient.send(method, headers: finalHeaders, to: "\(path)?\(query)", beforeSend: { $0.http.body = body }).flatMap({ response in
75-
guard response.http.status == .ok else {
79+
guard (200...299).contains(response.http.status.code) else {
7680
return try self.responseDecoder.decode(CloudStorageError.self, from: response.http, maxSize: 65_536, on: self.httpClient.container).map { error in
7781
throw error
7882
}.catchMap { error -> Response in

0 commit comments

Comments
 (0)