freshOS / Networking

⚡️ Concise networking code leveraging async-await, Decodable & Generics.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unexpected error message

workingDog opened this issue · comments

When I have a wifi connection the test code gives the correct "Unauthorized" error.
However when I disable the wifi, I get a "Unable To Parse Response".
I was expecting to get "Network Unreachable". It seems that the error in this case
is status+1.

Test code:

    import Foundation
    import Combine
    import SwiftUI
    import Networking

    struct ContentView: View {
    
    @State var cancellables = Set<AnyCancellable>()
    
    var body: some View {
        Text("Networking test").padding().onAppear(perform: {testNetwork()})
    }
    
    func testNetwork() {
        var client = NetworkingClient(baseURL: "https://api.github.com/")
        client.logLevels = .debug
        client.get("user").sink(receiveCompletion: { completion in
            switch completion {
            case .finished:
                break
            case .failure(let error):
                print("---> error: \(error) --> \(error.localizedDescription)")
                let netError = error as! NetworkingError
                print("---> netError.status: \(netError.status.rawValue)" )
            }
        }) { (data: Data) in
            print("---> data: \(data)" )
        }.store(in: &cancellables)
      }
    }

@workingDog Thanks a ton for noticing that and taking the time to report it. Being quite busy at the moment, would you be willing to fix this via a Pull Request ?

ok, I'll do it in the next few days.

@workingDog Any status on this? Was facing the same issue today trying to catch some timeout/no internet errors.

I have another question; is it possible to see where a mapping from JSON to object fails? Currently I'm only getting error 1 and "Unable To Parse Response". It would be great if I could see which parameter was wrong. I have a nested JSON structure with up to 5-6 levels so its quite cumbersome to troubleshoot. This is probably not related to this repo(?)

Status: I have a Pull Request that will fix most of these issues. Wait till s4cha review the PR. Look at my fork for more info in the meantime.

..."It would be great if I could see which parameter was wrong." Yes it would be. Careful investigation is the only way I know of.

Been working on Android for many years using RetroFit so I guess I'm a bit spoiled. Line-by-line ended up as my approach too.

I sometimes use quickType. For example, do:

curl "https://api.github.com/repos/workingDog/SPMExplorer"

copy and paste the json response into: https://app.quicktype.io/

to generate the bulk of the code.

Looking at this today, thanks a ton for your patience folks :)

@ScratchMyTail Indeed having the parsing bubble up would be great, this is not supported at the moment, I don't know if this is technically possible with Codable parsing to be honest. We'll track this one separately here: #16

@workingDog Can we close this since the related PR has already been merged ?

Yes, close this.