Skip to content

Commit

Permalink
Dispatch error handler on main queue
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Mar 27, 2019
1 parent fffe1f3 commit e786dc4
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions MapboxGeocoder/MBGeocoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,14 @@ open class Geocoder: NSObject {
request.setValue(userAgent, forHTTPHeaderField: "User-Agent")
return URLSession.shared.dataTask(with: request) { (data, response, error) in

guard let data = data else {
if let e = error as NSError? {
errorHandler(e)
} else {
let unexpectedError = NSError(domain: MBGeocoderErrorDomain, code: -1024, userInfo: [NSLocalizedDescriptionKey : "unexpected error", NSDebugDescriptionErrorKey : "this error happens when data task return nil data and nil error, which typically is not possible"])
errorHandler(unexpectedError)
guard let data = data else {
DispatchQueue.main.async {
if let e = error as NSError? {
errorHandler(e)
} else {
let unexpectedError = NSError(domain: MBGeocoderErrorDomain, code: -1024, userInfo: [NSLocalizedDescriptionKey : "unexpected error", NSDebugDescriptionErrorKey : "this error happens when data task return nil data and nil error, which typically is not possible"])
errorHandler(unexpectedError)
}
}
return
}
Expand Down

0 comments on commit e786dc4

Please sign in to comment.