Last active
March 14, 2020 10:58
-
-
Save raonivaladares/a303428e4c2c02d14165f313184e0d35 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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