2017-03-09 20 views
1

にエラーコードにアクセスしようとすると、私は私がAlamofire

print(response.debugDescription) 

を行うと、私は、コンソールでこのような何か持ってAlamofire 4を使用しています:

[Request]: https://api2.website.com 
[Response]: nil 
[Data]: 0 bytes 
[Result]: FAILURE: Error Domain=NSURLErrorDomain Code=-1009 "The Internet connection appears to be offline." UserInfo={NSUnderlyingError=0x17444ace0 {Error Domain=kCFErrorDomainCFNetwork Code=-1009 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x170490e50 [0x1ab165bb8]>{length = 16, capacity = 16, bytes = 0x100201bb341d1f890000000000000000}, _kCFStreamErrorCodeKey=57, _kCFStreamErrorDomainKey=1}}, NSErrorFailingURLStringKey=https://api2.flowwow.com/api2/client/info/?auth_token=da88d8aa49ff6f8bb4e1&hash=7f38be3f68db39a6d88687505fdb9ba5&partner_id=1004, NSErrorFailingURLKey=https://api2.website.com, _kCFStreamErrorDomainKey=1, _kCFStreamErrorCodeKey=57, NSLocalizedDescription=The Internet connection appears to be offline.} 
[Timeline]: Timeline: { "Request Start Time": 510763454.078, "Initial Response Time": 510763455.293, "Request Completed Time": 510763455.293, "Serialization Completed Time": 510763455.297, "Latency": 1.215 secs, "Request Duration": 1.215 secs, "Serialization Duration": 0.005 secs, "Total Duration": 1.220 secs } 

を、どの特定の行があります私に興味があります:

Error Domain=NSURLErrorDomain Code=-1009 

エラーを正しく処理できるように、このコードを取得する方法を教えてください。私が作ることができるすべての組み合わせを試しましたが、どこでもこのコードの痕跡はありません。

+0

私は([この質問/回答は]だと思いhttp://stackoverflow.com/questions/29131253/swift-alamofire-how-to-get-the-http-responseをお楽しみください。 -status-code)は有用かもしれないし、おそらく[this one](http://stackoverflow.com/questions/36331234/could-not-get-the-server-error-message-from-alamofire-3-3- 0)。 –

+0

@AhmadFええ、私は投稿する前にこれをチェックしました。それは助けになりませんでした。 – Edward

答えて

2

Alamofireで電話をすると、エラーを確認できる応答が返されます。これは、Alamofireでのエラー処理コールの簡単な例です。

Alamofire.request("https://your.url.com").responseJSON { response in 
    if (response.result.isSuccess){ 
     //do your json stuff 
    } else if (response.result.isFailure) { 
     //Manager your error 
     switch (response.error!._code){ 
      case NSURLErrorTimedOut: 
       //Manager your time out error 
       break 
      case NSURLErrorNotConnectedToInternet: 
       //Manager your not connected to internet error 
       break 
      default: 
       //manager your default case 
      } 
    } 
} 

:)