Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import XXClient
import Foundation
import XCTestDynamicOverlay
public struct UpdateErrors {
public enum Error: Swift.Error {
case noData
case decodeFailure
case network(URLError)
case bindingsException
}
public typealias Completion = (Result<Void, Error>) -> Void
public var run: (@escaping Completion) -> Void
public func callAsFunction(_ completion: @escaping Completion) -> Void {
run(completion)
}
}
extension UpdateErrors {
public static let live = UpdateErrors { completion in
let url = URL(string: "https://git.xx.network/elixxir/client-error-database/-/raw/main/clientErrors.json")
URLSession.shared.dataTask(with: url!) { data, _, error in
if let error {
completion(.failure(.network(error as! URLError)))
return
}
guard let data else {
completion(.failure(.noData))
return
}
guard let string = String(data: data, encoding: .utf8) else {
completion(.failure(.decodeFailure))
return
}
do {
try UpdateCommonErrors.live(jsonFile: string)
completion(.success(()))
} catch {
completion(.failure(.bindingsException))
}
}.resume()
}
}
extension UpdateErrors {
public static let unimplemented = UpdateErrors(
run: XCTUnimplemented("\(Self.self)")
)
}