Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit

Permalink
Fix build errors with Xcode 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Jun 6, 2023
1 parent c8e6504 commit ac22a61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Sources/Microya/Core/ApiError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import FoundationNetworking
/// Collection of all possible exception that can be thrown when using `JsonApi`.
public enum ApiError<ClientErrorType: Decodable>: Error, Sendable {
/// The request was sent, but the server response was not received. Typically an issue with the internet connection.
case noResponseReceived(error: Error?)
case noResponseReceived(error: (any Error)?)

/// The request was sent and the server responded, but the response did not include any body although a body was requested.
case noDataInResponse(statusCode: Int)

/// The request was sent and the server responded with a body, but the conversion of the body to the given type failed.
case responseDataConversionFailed(type: String, error: Error)
case responseDataConversionFailed(type: String, error: any Error)

/// The request was sent and the server responded, but the server reports that something is wrong with the request.
case clientError(statusCode: Int, clientError: ClientErrorType?)
Expand Down
15 changes: 10 additions & 5 deletions Sources/Microya/Core/ApiProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ open class ApiProvider<EndpointType: Endpoint> {
public typealias TypedResult<T: Decodable> = Result<T, ApiError<EndpointType.ClientErrorType>>

/// The lower level Result structure received directly from the native `URLSession` data task calls.
public typealias URLSessionResult = (data: Data?, response: URLResponse?, error: Error?)
public typealias URLSessionResult = (data: Data?, response: URLResponse?, error: (any Error)?)

/// The plugins to apply per request.
public let plugins: [Plugin<EndpointType>]
Expand Down Expand Up @@ -188,7 +188,7 @@ open class ApiProvider<EndpointType: Endpoint> {
plugin.willPerformRequest(request, endpoint: endpoint)
}

func handleResponse(data: Data?, response: URLResponse?, error: Error?) -> TypedResult<ResultType> {
func handleResponse(data: Data?, response: URLResponse?, error: (any Error)?) -> TypedResult<ResultType> {
let urlSessionResult: URLSessionResult = (data: data, response: response, error: error)
let typedResult: TypedResult<ResultType> = self.decodeBody(from: urlSessionResult, endpoint: endpoint)

Expand Down Expand Up @@ -290,7 +290,7 @@ open class ApiProvider<EndpointType: Endpoint> {
plugin.willPerformRequest(request, endpoint: endpoint)
}

func handleDataTaskCompletion(data: Data?, response: URLResponse?, error: Error?) {
func handleDataTaskCompletion(data: Data?, response: URLResponse?, error: (any Error)?) {
let urlSessionResult: URLSessionResult = (data: data, response: response, error: error)
let typedResult: TypedResult<ResultType> = self.decodeBody(from: urlSessionResult, endpoint: endpoint)

Expand Down Expand Up @@ -373,7 +373,7 @@ open class ApiProvider<EndpointType: Endpoint> {
}
}

private func mapToClientErrorType(error: Error) -> ApiError<EndpointType.ClientErrorType> {
private func mapToClientErrorType(error: any Error) -> ApiError<EndpointType.ClientErrorType> {
.noResponseReceived(error: error)
}

Expand Down Expand Up @@ -518,7 +518,12 @@ extension ApiProvider {
for plugin in plugins {
plugin.willPerformRequest(urlRequest, endpoint: endpoint)
}
func handleResponse<ResultType: Decodable>(on endpoint: EndpointType, data: Data?, response: URLResponse?, error: Error?) -> TypedResult<ResultType> {
func handleResponse<ResultType: Decodable>(
on endpoint: EndpointType,
data: Data?,
response: URLResponse?,
error: (any Error)?
) -> TypedResult<ResultType> {
let urlSessionResult: URLSessionResult = (data: data, response: response, error: error)
let typedResult: TypedResult<ResultType> = self.decodeBody(from: urlSessionResult, endpoint: endpoint)

Expand Down
2 changes: 1 addition & 1 deletion Tests/MicroyaTests/Supporting/TestDataStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import FoundationNetworking

enum TestDataStore {
static var request: URLRequest?
static var urlSessionResult: (data: Data?, response: URLResponse?, error: Error?)?
static var urlSessionResult: (data: Data?, response: URLResponse?, error: (any Error)?)?
static var showingProgressIndicator: Bool = false

static func reset() {
Expand Down

0 comments on commit ac22a61

Please sign in to comment.