How do you differentiate network and server errors in suspend functions?

WHAT IT TESTS: Structured error handling in coroutines and mapping exceptions to recovery. ANSWER OUTLINE: Catch IOException for connectivity and HttpException for HTTP errors; wrap in a sealed Result. RED FLAG: Catching Exception or exposing raw errors to UI.
WHAT IT TESTS: Whether you understand structured error handling in Kotlin coroutines and can map exception types to appropriate recovery strategies. ANSWER OUTLINE: Catch IOException for connectivity and HttpException for server errors like 404 or 500; wrap them in a sealed Result class so the UI sees domain errors, not Retrofit implementation details. RED FLAG: Catching generic Exception, exposing raw library exceptions directly to ViewModels, or retrying every failure blindly.
Read the original → developer.android.com
- #kotlin
- #coroutines
- #error-handling
- #retrofit
- #android
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.