steamclock / netable

A Swift library for encapsulating network APIs using Codable in a type-oriented way.
MIT License
99 stars 3 forks source link

Another attempt at handling expected errors. #50

Closed brendanlensink closed 4 years ago

brendanlensink commented 4 years ago

Continuing the discussion from #47.

Adds a new optional field to Request, public var expectedErrorResponses: [ExpectedErrorResponse]

public struct ExpectedErrorResponse {
    var code: Int
    var handler: (Data?) -> Void
}

This is also a little clunky, but you end up declaring your expected error response handlers in the Request constructor.

Thoughts? @nbrooke

nbrooke commented 4 years ago

Yeah, maybe having a generic way to do this is just tilting at windmills. It seems like most of the potential approaches here end up being at least as verbose / gross as just doing what we are now and pulling apart the http error case and manually handling the response Data.

The original bug for this was more driven by me thinking "hey, maybe it would be nice if this were a little more automatic" rather than having a specific use case that would benefit from handling it inside the library, I'm sort of inclined to just say these two experiments demonstrate that this is simple enough that a more general purpose approach isn't actually better, and just close the original bug.