Skip to content

Commit 02d929e

Browse files
author
Saul Urias
committed
Added case errror: Unable To Find Location
1 parent 799c632 commit 02d929e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

SwiftWeather/Error.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ struct SWError {
1111
case networkRequestFailed = -6001
1212
case jsonSerializationFailed = -6002
1313
case jsonParsingFailed = -6003
14+
case unableToFindLocation = -6004
1415
}
1516

1617
let errorCode: Code

SwiftWeather/LocationService.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import CoreLocation
88

99
protocol LocationServiceDelegate {
1010
func locationDidUpdate(_ service: LocationService, location: CLLocation)
11+
func locationDidFail(withError error: SWError)
1112
}
1213

1314
class LocationService: NSObject {
@@ -38,6 +39,8 @@ extension LocationService : CLLocationManagerDelegate {
3839
}
3940

4041
func locationManager(_ manager: CLLocationManager, didFailWithError error: Error) {
42+
let swError = SWError(errorCode: .unableToFindLocation)
43+
delegate?.locationDidFail(withError: swError)
4144
print("Error finding location: \(error.localizedDescription)")
4245
}
4346
}

SwiftWeather/WeatherViewModel.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,10 @@ class WeatherViewModel {
7171
errorMessage.value = "We're having trouble processing weather data."
7272
case .jsonParsingFailed:
7373
errorMessage.value = "We're having trouble parsing weather data."
74+
case .unableToFindLocation:
75+
errorMessage.value = "We're having trouble getting user location."
7476
}
75-
77+
7678
location.value = emptyString
7779
iconText.value = emptyString
7880
temperature.value = emptyString
@@ -98,4 +100,8 @@ extension WeatherViewModel: LocationServiceDelegate {
98100
})
99101
}
100102
}
103+
104+
func locationDidFail(withError error: SWError) {
105+
self.update(error)
106+
}
101107
}

0 commit comments

Comments
 (0)