My following code throws an exception instead of showing the response:
fun getRoadStatus(roadName: String) {
// Couroutine to fetch data from the API
viewModelScope.launch {
try{
_busy.value = true
println("Getting result")
_dataObject.value = MyApi.retrofitService.getRoadStatus(roadName)[0]
_busy.value = false
} catch (e:Exception) {
println(e)
_busy.value = false
}
}
}
my _dataObject.value should be loaded with data sent from the server with a message and status code of 404 but instead my code enters into an Exception with a 404. How can access my object data for this error from the server please?