It looks like you're confused with error handling techniques.
Take a quick peek at the documentation for dataTask(with:)
Apple Documentation: dataTask(with:)
// funtion's signature
func dataTask(with request: URLRequest, completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void)
This function's signature tells you that dataTask takes two parameters: the URLRequest object, and a function that you provide. Remember! Functions are first class objects in Swift. You can create them and pass them around as variables.
The function you provide must accept three parameters: a Data object, a URLResponse object, and an Error object. Actually, they are all optionals, so you may get nils instead of actual objects.
What does your function return? Void! nada. zilch. Nut-N-Honey.
Notice the function's signature doesn't say it throws! This means if it detects an error, the function won't abrubtly stop and burp out an error message you have to catch and interpret. Instead, this function is designed to return an Error object. Instead of catching an error, you need to take a look at the error parameter and see if anything's inside the box.
// Here's an example of a function signature that throws
init(contentsOfFile path: String) throws
Because dataTask(with:) doesn't throw errors, there is nothing for your method to catch, as @hatsushira points out. Since there is nothing to catch, the compiler warns you that your onFailure(error) code will never be executed.
Paul has a nice article on do / try / catch. Do / Catch
In your code, this section essentially checks for errors from your URLRequest:
if let error = error { // Sure enough! error has something in it. It's NOT nil!
onFailure(error) // open the error box and take a look inside.
// Probably should exit here.
}
This section then verifies you received data:
if let data = data { // Yup! There's something in the data package left at the front door.
onSuccess(data) // Open it up and see what's inside.
}