title: In Swift, how do you get the error type from UrlSession
body: <p>I have the following code in my network logic:</p>
  <pre><code>let task = urlSession.dataTask(with: request) { [weak self] (data, response, error) in
    
    if let error = error {        
      if error.localizedDescription.contains(&quot;The request timed out&quot;) {
        // request timeout stuff ...
      } else {
        // other errors
      }
    }
  }
  </code></pre>
  <p>String matching <code>localizedDescription</code> is not good code practice. How do I get the type of the error just like in <code>catch</code> clauses?</p>