afterxleep / WireKit

A simple Swift Networking library for consuming REST API's

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decode body of errors

mazz opened this issue · comments

Some servers return a body message on errors(>299).

        return urlSession
            .dataTaskPublisher(for: request)
            .tryMap({ data, response in
                if let response = response as? HTTPURLResponse,
                 !(200...299).contains(response.statusCode) {
                    throw httpError(response.statusCode)
                }
                return data
            })
            .decode(type: ReturnType.self, decoder: decoder)
            .mapError { error in
               handleError(error)
            }
            .eraseToAnyPublisher()

The above code chunk in dispatch() only returns data on codes between 200...299.

It would be great if the library would return both data and error with errors >299.

Than you for the suggestion. Sorry it took me so long to see this. I'll add it to my list.

Done!. This is included in 1.0.4