I have a protocol that contains two functions successWeather and errorWeather. When the status code returns something other than 200-299 I want it to throw the errorWeather function.
My question is: How can I force an error if the guard catches the status code? As of now, error returns nil.
func errorWeather(error: NSError)
let task = URLSession.shared.dataTask(with: request) { (data, response, error) -> Void in
        if let error = error {
            self.delegate.errorWeather(error: error as! NSError)
        }
        guard let statusCode = (response as? HTTPURLResponse)?.statusCode, statusCode >= 200 && statusCode <= 299 else {
            print("Your request returned a status code other than 2xx!")
            //How can I force an error?
            return
        }
 
    