Better file caching and update management

This commit is contained in:
Vicnet
2023-12-14 14:11:56 +01:00
parent 899dc20e55
commit a3fc891d0a
23 changed files with 592 additions and 483 deletions

View File

@@ -77,10 +77,14 @@ struct ApiRequest {
do {
(data, response) = try await URLSession.shared.data(for: request)
Logger.network.debug("\(method.rawValue) \(path) SUCCESS!")
if let error = decodeURLResponse(response: response as? HTTPURLResponse) {
print("\(method.rawValue) \(path) FAILURE: \(error.localizedDescription)")
return (nil, error)
}
if let data = data {
print(data, String(data: data, encoding: .utf8))
}
return (data, nil)
return (data!, nil)
} catch {
let error = decodeURLResponse(response: response as? HTTPURLResponse)
Logger.network.debug("\(method.rawValue) \(path) FAILURE: \(error.debugDescription)")
@@ -92,6 +96,7 @@ struct ApiRequest {
guard let response = response else {
return NetworkError.unknownError
}
print("Status code: ", response.statusCode)
switch response.statusCode {
case 200...299: return (nil)
case 300...399: return (NetworkError.redirectionError)