Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected error message #10

Closed
workingDog opened this issue Oct 26, 2020 · 11 comments
Closed

unexpected error message #10

workingDog opened this issue Oct 26, 2020 · 11 comments

Comments

@workingDog
Copy link
Contributor

workingDog commented Oct 26, 2020

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)
      }
    }
@s4cha
Copy link
Member

s4cha commented Oct 27, 2020

@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 ?

@workingDog
Copy link
Contributor Author

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

@ScratchMyTail
Copy link

@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(?)

@workingDog
Copy link
Contributor Author

workingDog commented Oct 30, 2020

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.

@workingDog
Copy link
Contributor Author

..."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.

@ScratchMyTail
Copy link

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.

@workingDog
Copy link
Contributor Author

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.

@s4cha
Copy link
Member

s4cha commented Nov 11, 2020

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

@s4cha
Copy link
Member

s4cha commented Nov 11, 2020

@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

@s4cha
Copy link
Member

s4cha commented Nov 19, 2020

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

@workingDog
Copy link
Contributor Author

Yes, close this.

@s4cha s4cha closed this as completed Nov 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants