Fix crash on loading App Store search results

This commit is contained in:
relikd
2020-09-08 11:52:07 +02:00
parent 6409e5eaf3
commit fb680d669b
4 changed files with 51 additions and 27 deletions

View File

@@ -20,15 +20,15 @@ struct AppStoreSearch {
let developer, imageURL: String?
}
static func search(_ term: String, _ closure: @escaping ([Result]?) -> Void) {
static func search(_ term: String, _ closure: @escaping ([Result]?, Error?) -> Void) {
URLSession.shared.dataTask(with: .init(url: .appStoreSearch(query: term))) { data, response, error in
guard let data = data, error == nil,
let response = response as? HTTPURLResponse,
(200 ..< 300) ~= response.statusCode else {
closure(nil)
closure(nil, error ?? URLError(.badServerResponse))
return
}
closure(jsonSearchToList(data))
closure(jsonSearchToList(data), nil)
}.resume()
}

View File

@@ -98,9 +98,7 @@ struct BundleIcon {
return img
}
static func download(_ bundleId: String, urlStr: String, whenDone: @escaping () -> Void) {
if let url = URL(string: urlStr) {
url.download(to: local(bundleId), onSuccess: whenDone)
}
static func download(_ bundleId: String, url: URL, whenDone: @escaping () -> Void) -> URLSessionDownloadTask {
return url.download(to: local(bundleId), onSuccess: whenDone)
}
}