Error Domain=NSURLErrorDomain Code=-1000 "bad URL"

Some mobile phones frequently report an error "bad URL" with the domain set to NSURLErrorDomain and the code set to -1000. However, I never encounter this error, and I'm not sure what's going wrong,The error log is as follows:

HttpInterceptor:81 didReceive(_:target:): moya error: underlying(Alamofire.AFError.sessionTaskFailed(error: Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo={_kCFStreamErrorCodeKey=22, NSUnderlyingError=0x1119f91d0 {Error Domain=kCFErrorDomainCFNetwork Code=-1000 "(null)" UserInfo={_NSURLErrorNWPathKey=satisfied (Path is satisfied), interface: utun4[endc_sub6], ipv4, dns, uses cell, LQM: unknown, _kCFStreamErrorCodeKey=22, _kCFStreamErrorDomainKey=1}}, _NSURLErrorFailingURLSessionTaskErrorKey=LocalDataTask <7FF86D00-1379-43D4-9F9B-0C300AEC57C8>.<4>, _NSURLErrorRelatedURLSessionTaskErrorKey=( "LocalDataTask <7FF86D00-1379-43D4-9F9B-0C300AEC57C8>.<4>" ), NSLocalizedDescription=bad URL, NSErrorFailingURLStringKey=https://update.flashforge.com/api/updates/check?app_id=46&entity_id=9E8D3B0C-2E61-46AF-91B9-B4AFFACF2788&platform=23&version=v1.3.4, NSErrorFailingURLKey=https://update.flashforge.com/api/updates/check?app_id=46&entity_id=9E8D3B0C-2E61-46AF-91B9-B4AFFACF2788&platform=23&version=v1.3.4, _kCFStreamErrorDomainKey=1}), nil)

Hmmm, tricky. Error -1000 is NSURLErrorBadURL (or, equivalently, kCFURLErrorBadURL). There are a variety of ways this can crop up, for example:

  • If the resulting NSURLRequest returns nil for the URL property.
  • If the URL’s host property is nil.
  • Or the system is configured to use a proxy and its host property is nil.

It’s not easy to replicate these conditions. Moreover, the full error message you included in your post rules out the first two cases because it shows this:

NSErrorFailingURLStringKey=https://update.flashforge.com/api/…

In this thread I raise two possible causes of this, Custom URL protocols and proxies. I recommend that you check your code for the former, just in case. However, given that this only shows up on some user’s devices, it seems like a proxy problem is more likely.

Are you able to capture a sysdiagnose log from a user who has this issue?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Error Domain=NSURLErrorDomain Code=-1000 "bad URL"
 
 
Q