Skip to content

Commit

Permalink
Pass HTTPURLResponse to Response
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Dec 10, 2021
1 parent 5da47d5 commit 8005e5b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Sources/APIClient/APIClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public actor APIClient {
delegate.client(self, willSendRequest: &request)
let (data, response) = try await session.data(for: request, delegate: nil)
try validate(response: response, data: data)
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 200 // The right side should never be executed
return Response(value: data, data: data, request: request, response: response, statusCode: statusCode)
let httpResponse = (response as? HTTPURLResponse) ?? HTTPURLResponse() // The right side should never be executed
return Response(value: data, data: data, request: request, response: httpResponse, statusCode: httpResponse.statusCode)
}

private func makeRequest<T>(for request: Request<T>) async throws -> URLRequest {
Expand Down
2 changes: 1 addition & 1 deletion Sources/APIClient/Request.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public struct Response<T> {
public let data: Data
/// Original request.
public let request: URLRequest
public let response: URLResponse
public let response: HTTPURLResponse
public let statusCode: Int

func map<U>(_ closure: (T) -> U) -> Response<U> {
Expand Down

0 comments on commit 8005e5b

Please sign in to comment.