Catch Network & Parsing Errors
Convert Ktor and serializer exceptions to results.
Where Errors Begin
Most failures appear at two spots: the network call and the JSON parse. Catching them here keeps the rest of your shared code clean and calm.
Wrap the Risky Call
Put the Ktor request and the decode inside a single try block. One guarded spot is easier to reason about than scattered checks.
try {
val user = client.get(url).body<User>()
} catch (e: Exception) { }All lessons in this course
- A Sealed Result Type
- Catch Network & Parsing Errors
- Map Errors to UI Messages
- Retry & Offline Fallbacks