OK, I just fell in 😍 with stdlib’s Result(catching:)
.
extension Request where Response: Decodable {
func handle(response: Result<Data, Error>,
completion: (Result<Response, Error>) -> Void) {
completion(Result {
try JSONDecoder().decode(Response.self, from: response.get())
})
}
}