Error Handling
Prinsip
- Never swallow errors — Jangan biarkan catch block kosong.
- User-friendly messages — Tampilkan pesan error yang bisa dipahami user.
- Logging — Log error secara detail untuk debugging (tapi jangan log sensitive data).
- Retry mechanism — Berikan opsi retry untuk recoverable errors.
- Graceful degradation — Tampilkan cached data jika network gagal.
Error Classification
| Tipe Error | Contoh | Handling |
|---|---|---|
| Network Error | No internet, timeout | Show retry button + cached data |
| Server Error (5xx) | Internal server error | Show generic error + retry |
| Client Error (4xx) | Validation, unauthorized | Show specific error message |
| Auth Error (401/403) | Token expired | Auto refresh token / redirect to login |
| Parse Error | Malformed JSON | Log error + show generic message |
| Unknown Error | Unexpected exception | Log to crash reporting + generic message |
Error UI States
Setiap screen harus menangani:
- Loading — Skeleton / shimmer / spinner
- Success — Tampilkan data
- Empty — Tampilkan empty state illustration + message
- Error — Tampilkan error message + retry button
- No Internet — Tampilkan offline indicator + cached data (jika ada)