2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

dataTaskWithURLメソッドが吐き出すエラーの例

Posted at

NSURLSession.sharedSession()で取得したsessionオブジェクトのdataTaskWithURLメソッドが失敗した時に吐き出されるエラーは、こんな感じです。(xcode7 beta + Swift2.0)

  • NSErrorを取り出すコードの断片
foo.swift
let session = NSURLSession.sharedSession()                                      
let task = session.dataTaskWithURL(url,
  completionHandler: { data, response, error in
if error != nil {
  print("err descpription = \(error!.description)")
  print("err = \(error!.localizedDescription)")
  print("err code = \(error!.code)")
  print("err domain = \(error!.domain)")
  print("err userInfo = \(error!.userInfo)")
}

  • debug consoleの出力
foo.swift
2015-06-23 13:49:10.814 xxx[4869:202756] CFNetwork SSLHandshake failed (-9824)
2015-06-23 13:49:10.827 xxx[4869:202756] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9824)

err descpription = Error Domain=NSURLErrorDomain Code=-1200 "An SSL error has occurred and a secure connection to the server cannot be made." UserInfo=0x7fe20be44500 {_kCFStreamErrorCodeKey=-9824, NSLocalizedRecoverySuggestion=Would you like to connect to the server anyway?, NSUnderlyingError=0x7fe20be3eec0 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1200.)", NSLocalizedDescription=An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey=https://www.apple.com/, NSErrorFailingURLStringKey=https://www.apple.com/, _kCFStreamErrorDomainKey=3}

err = An SSL error has occurred and a secure connection to the server cannot be made.

err code = -1200

err domain = NSURLErrorDomain

err userInfo = [_kCFStreamErrorCodeKey: -9824, NSLocalizedRecoverySuggestion: Would you like to connect to the server anyway?, NSUnderlyingError: Error Domain=kCFErrorDomainCFNetwork Code=-1200 "The operation couldn’t be completed. (kCFErrorDomainCFNetwork error -1200.)" UserInfo=0x7fe20be3ec00 {_kCFStreamPropertySSLClientCertificateState=0, _kCFNetworkCFStreamSSLErrorOriginalValue=-9824, _kCFStreamErrorDomainKey=3, _kCFStreamErrorCodeKey=-9824}, NSLocalizedDescription: An SSL error has occurred and a secure connection to the server cannot be made., NSErrorFailingURLKey: https://www.apple.com/, NSErrorFailingURLStringKey: https://www.apple.com/, _kCFStreamErrorDomainKey: 3]

このあたりは、Swift2のバージョンが上がるに従いthrowsへ書き直される予感!

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?