Skip to content

Commit

Permalink
Merge pull request #14 from vapor-community/empty-response-decoding
Browse files Browse the repository at this point in the history
Fixed Decoding EmptyResponse Type
  • Loading branch information
Andrewangeta authored Dec 17, 2018
2 parents 85567da + cbf9291 commit 599a135
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Sources/GoogleCloud/Storage/StorageRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ public final class GoogleCloudStorageRequest {
func send<GCM: GoogleCloudModel>(method: HTTPMethod, headers: HTTPHeaders = [:], path: String, query: String, body: HTTPBody = HTTPBody()) throws -> Future<GCM> {
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)
})
})
Expand Down Expand Up @@ -72,7 +76,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
Expand Down

0 comments on commit 599a135

Please sign in to comment.