💚 Add linux support
Some checks failed
Hermes CI / build (push) Failing after 3m11s

This commit is contained in:
Victor Bodinaud
2024-01-14 22:17:25 +01:00
parent cfbdf160e8
commit cbc777ed88

View File

@@ -104,7 +104,24 @@ public struct Hermes {
request.addValue(header.value, forHTTPHeaderField: header.key)
}
let (data, response) = try await URLSession.shared.data(for: request)
let task = URLSession.shared.dataTask(with: request) { data, response, error in
guard let responseData = data, error == nil else {
completion(.failure(error ?? NetworkRequestError.unknown(data, response)))
return
}
guard let _ = response as? HTTPURLResponse else {
throw NetworkError.invalidResponse
}
guard let result = try? JSONDecoder().decode(resource.modelType, from: data) else {
throw NetworkError.decodingError
}
completion(.success(result))
}
task.resume()
#else
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = defaultHeaders
@@ -112,7 +129,6 @@ public struct Hermes {
let session = URLSession(configuration: configuration)
let (data, response) = try await session.data(for: request)
#endif
guard let _ = response as? HTTPURLResponse else {
throw NetworkError.invalidResponse
@@ -123,5 +139,6 @@ public struct Hermes {
}
return result
#endif
}
}