delannoyk / SoundcloudSDK

A Client for Soundcloud's API written in Swift!
MIT License
87 stars 27 forks source link

How get NSError from SoundcloudError? #52

Closed Alexandeer closed 7 years ago

delannoyk commented 7 years ago

@Alexandeer Hey,

Here's an example:

Track.relatedTracks(identifier: 123456) { simpleAPIResponse in
    switch simpleAPIResponse. response {
    case .success(let tracks):
        //do whatever
    case .failure(let error):
        //here's the error.
    }
}
Alexandeer commented 7 years ago

You kidding me ) Try get error.code in .failure. For example for cancel request:

let r = Track.relatedTracks(identifier: 123456) { simpleAPIResponse in
    switch simpleAPIResponse. response {
    case .success(let tracks):
        //do whatever
    case .failure(let error):
       let nserror = error as NSError
       if error.code == -999 {
          print("delannoyk")
       }
    }
}
r.cancel()

@delannoyk, I fixed it for self, but I want to see your a variant