in src/main/kotlin/org/jetbrains/plugins/template/weatherApp/ui/WeatherAppViewModel.kt [285:302]
override fun onLoadWeatherForecast(location: Location) {
currentWeatherJob?.cancel()
currentWeatherJob = viewModelScope.launch {
_weatherState.value = WeatherForecastUIState.Loading(location)
weatherService.loadWeatherForecastFor(location)
.onSuccess { weatherData ->
_weatherState.value = WeatherForecastUIState.Success(weatherData)
}.onFailure { error ->
if (error is CancellationException) {
throw error
}
_weatherState.value = errorStateFor(location, error)
}
}
}