Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save raonivaladares/a303428e4c2c02d14165f313184e0d35 to your computer and use it in GitHub Desktop.
Save raonivaladares/a303428e4c2c02d14165f313184e0d35 to your computer and use it in GitHub Desktop.
func execute(
with urlRquest: URLRequest,
completion: @escaping (Result<Data, NetworkPlataformError>) -> Void) {
urlSession.dataTask(with: urlRquest) { data, urlResponse, error in
if let error = error {
let errorParsed = NetworkPlataformErrorParser().parse(error)
completion(.failure(errorParsed))
return
}
guard let urlResponse = urlResponse else {
completion(.failure(.unkown))
return
}
if let errorFromURLResponse = URLResponseErrorParser()
.parseErrorIfExists(on: urlResponse) {
completion(.failure(errorFromURLResponse))
return
}
if let data = data {
completion(.success(data))
} else {
completion(.failure(.unkown))
}
}.resume()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment