SDWebImageErrorDomain

SDCycleScrollViewSDWebImage 是 iOS 开发很常用的两个框架,做图片轮播、图标缓存时最常用。前几天突然报错了,轮播图片加载不出来,查看 Log 的错误信息也是哭笑不得了…

测试的同事反馈,轮播图片一直不显示,主要的错误信息就是 SDWebImageErrorDomain

前期提示:

1
Error Domain=SDWebImageErrorDomain Code=2002 "Operation cancelled by user during sending the request" UserInfo={NSLocalizedDescription=Operation cancelled by user during sending the request}

连续刷新测试提示:

1
Error Domain=SDWebImageErrorDomain Code=1003 "Image url is blacklisted" UserInfo={NSLocalizedDescription=Image url is blacklisted}

偶尔提示:

1
2
3
Error Domain=NSURLErrorDomain Code=-1017 "无法解析响应" UserInfo={_kCFStreamErrorCodeKey=-1, NSUnderlyingError=0x282ea4660 {Error Domain=kCFErrorDomainCFNetwork Code=-1017 "(null)" UserInfo={NSErrorPeerAddressKey=<CFData 0x2802f6bc0 [0x2133ecfd0]>{length = 16, capacity = 16, bytes = 0x100222b8c0a81dc40000000000000000}, _kCFStreamErrorCodeKey=-1, _kCFStreamErrorDomainKey=4}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <78D3EF9A-BA05-43FC-B373-740CE983D263>.<1>, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDataTask <78D3EF9A-BA05-43FC-B373-740CE983D263>.<1>"
), NSLocalizedDescription=无法解析响应, NSErrorFailingURLStringKey=https://xxx.xxx.xx/xx/xx, NSErrorFailingURLKey=https://xxx.xxx.xx/xx/xx, _kCFStreamErrorDomainKey=4}

乍一看莫名其妙的,网络抓包看一下,其实是因为网络请求失败了,访问图片的 URL 需要过认证,但是客户端缺少了一个 cookie,被重定向到业务系统的登录页面了…然后同一个服务出现太多次请求失败, SDWebImage 就会中断异常的请求、甚至“拉黑”,哈哈。「无法解析响应」是服务端的问题,传过来的图片流被中断了EOF: Premature EOF encountered 或者 transfer closed with outstanding read data remaining