💚 Try something else
Some checks failed
Hermes CI / build (push) Failing after 40s

This commit is contained in:
Victor Bodinaud
2024-01-14 21:53:50 +01:00
parent 0b49cd85f8
commit 2e77da22c8

View File

@@ -5,7 +5,7 @@
//
import Foundation
#if canImport(FoundationNetworking)
#if os(Linux)
import FoundationNetworking
#endif
@@ -19,15 +19,15 @@ public enum NetworkError: Error {
extension NetworkError: LocalizedError {
public var errorDescription: String? {
switch self {
case .badRequest:
return NSLocalizedString("Unable to perform request", comment: "badRequestError")
case .serverError(let errorMessage):
print(errorMessage)
return NSLocalizedString(errorMessage, comment: "serverError")
case .decodingError:
return NSLocalizedString("Unable to decode successfully", comment: "decodingError")
case .invalidResponse:
return NSLocalizedString("Invalid response", comment: "invalidResponse")
case .badRequest:
return NSLocalizedString("Unable to perform request", comment: "badRequestError")
case .serverError(let errorMessage):
print(errorMessage)
return NSLocalizedString(errorMessage, comment: "serverError")
case .decodingError:
return NSLocalizedString("Unable to decode successfully", comment: "decodingError")
case .invalidResponse:
return NSLocalizedString("Invalid response", comment: "invalidResponse")
}
}
}
@@ -39,12 +39,12 @@ public enum HTTPMethod {
var name: String {
switch self {
case .get:
return "GET"
case .post:
return "POST"
case .delete:
return "DELETE"
case .get:
return "GET"
case .post:
return "POST"
case .delete:
return "DELETE"
}
}
}
@@ -82,9 +82,9 @@ public struct Hermes {
var request = URLRequest(url: resource.url)
switch resource.method {
case .get(let queryItems):
var components = URLComponents(url: resource.url, resolvingAgainstBaseURL: false)
components?.queryItems = queryItems
case .get(let queryItems):
var components = URLComponents(url: resource.url, resolvingAgainstBaseURL: false)
components?.queryItems = queryItems
guard let url = components?.url else {
throw NetworkError.badRequest
}
@@ -99,11 +99,20 @@ public struct Hermes {
request.httpMethod = resource.method.name
}
#if os(Linux)
for header in defaultHeaders {
request.addValue(header.value, forHTTPHeaderField: header.key)
}
let (data, response) = try await URLSession.shared.data(for: request)
#else
let configuration = URLSessionConfiguration.default
configuration.httpAdditionalHeaders = defaultHeaders
let session = URLSession(configuration: configuration)
let (data, response) = try await session.data(for: request)
#endif
guard let _ = response as? HTTPURLResponse else {
throw NetworkError.invalidResponse