             
             completion?(nil, .requestFailed)
         }
-        
-        dataTask.resume()
-        
-        return dataTask
     }
 }


import Foundation

typealias NewsProviderRequestCallback = (((Data?, NewsAPIError?) -> ()))?

class NewsProvider {
    private let apiKey: String

    }
    
    @discardableResult
    func request(_ target: NewsAPITarget, completion: NewsProviderRequestCallback?) -> URLSessionDataTask? {
        guard let urlRequest = makeUrlRequest(with: target) else {
            completion?(nil, .unknown)
            return nil
        }
        
        let completionHandler = makeDataTaskCompletionHandler(completion: completion)
        let dataTask = urlSession.dataTask(with: urlRequest, completionHandler: completionHandler)
        
        dataTask.resume()
        
        return dataTask
    }
}

private extension NewsProvider {
    func makeUrlRequest(with target: NewsAPITarget) -> URLRequest? {
        let urlRequestBuilder = URLRequestBuilder(url: target.endpoint, headers: ["X-Api-Key": apiKey])
        return URLRequest(builder: urlRequestBuilder)
    }
    
    func makeDataTaskCompletionHandler(completion: NewsProviderRequestCallback?) -> ((Data?, URLResponse?, Error?) -> ()) {
        return { data, response, error in
            if let data = data {
                completion?(data, nil)
                return
