This commit is contained in:
@@ -5,9 +5,6 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
#if os(Linux)
|
|
||||||
import FoundationNetworking
|
|
||||||
#endif
|
|
||||||
|
|
||||||
public enum NetworkError: Error {
|
public enum NetworkError: Error {
|
||||||
case badRequest
|
case badRequest
|
||||||
@@ -99,30 +96,6 @@ public struct Hermes {
|
|||||||
request.httpMethod = resource.method.name
|
request.httpMethod = resource.method.name
|
||||||
}
|
}
|
||||||
|
|
||||||
#if os(Linux)
|
|
||||||
for header in defaultHeaders {
|
|
||||||
request.addValue(header.value, forHTTPHeaderField: header.key)
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
let configuration = URLSessionConfiguration.default
|
||||||
configuration.httpAdditionalHeaders = defaultHeaders
|
configuration.httpAdditionalHeaders = defaultHeaders
|
||||||
|
|
||||||
@@ -139,6 +112,5 @@ public struct Hermes {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user