0Pricing
Kotlin Multiplatform Academy · Lekcja

Mapowanie błędów na komunikaty interfejsu

Zamiana niepowodzeń na zlokalizowane, przyjazne użytkownikowi teksty

Mapowanie błędów na komunikaty interfejsu to bezpłatna lekcja Kotlin Multiplatform Academy na CoddyKit. To lekcja 3 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Kotlin Multiplatform Academy, a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Kotlin Multiplatform Academy zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

Raw Errors Are Cryptic

A user should never see SerializationException on screen. Your job is to translate technical failures into calm, human sentences.

Define Friendly Categories

Group failures into a few error kinds like network, server and unknown. Each kind maps to one clear message the apps can show.

enum class ErrorKind { NETWORK, SERVER, UNKNOWN }

Carry the Kind in Failure

Extend your Failure to hold an ErrorKind, not just a raw string. The UI then decides wording instead of trusting backend text.

data class Failure(val kind: ErrorKind) : Result<Nothing>()

Map at the Boundary

Convert exceptions to an ErrorKind right where you catch them. After this point your code speaks only in friendly, stable categories.

catch (e: IOException) {
  Failure(ErrorKind.NETWORK)
}

A Message Lookup

Write one function that turns an ErrorKind into display text. Keep it in shared code so both apps phrase errors identically.

fun message(k: ErrorKind): String

Localize the Text

Real apps translate messages. Let each platform localize the kind, so the shared layer passes the category and the UI picks the language.

Keep Strings Out of Logic

Your rules return an ErrorKind, never a hardcoded sentence. Wording can change anytime without touching business logic.

Different Kinds, Different UI

A network error might show a retry button while a server error shows a support link. The kind drives both the words and the action.

Fallback for the Unknown

Always include an UNKNOWN kind. Unexpected failures still get a polite, generic message instead of a blank or scary screen.

Test the Mapping

Because the mapper is pure, you can test it in commonTest: feed an exception, assert the kind, with no UI or device involved.

One Source of Truth

Now errors travel as typed kinds from catch to screen, giving Android and iOS one consistent, friendly story for every failure.

Quick Check

Consider what the shared layer should expose to the UI.

Recap

You categorized failures into ErrorKinds, mapped exceptions at the boundary, and let each UI localize and act on the kind for a friendly experience. 💬

Często zadawane pytania

Czy lekcja „Mapowanie błędów na komunikaty interfejsu” jest bezpłatna?

Tak — pełny tekst „Mapowanie błędów na komunikaty interfejsu” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Kotlin Multiplatform Academy, przejdź na CoddyKit PRO. Kurs Kotlin Multiplatform Academy zawiera 4 lekcji w sumie.

Co nauczysz się w „Mapowanie błędów na komunikaty interfejsu”?

Zamiana niepowodzeń na zlokalizowane, przyjazne użytkownikowi teksty Ćwiczysz Kotlin Multiplatform Academy z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Kotlin Multiplatform Academy?

Nie wymagamy żadnego doświadczenia. Kotlin Multiplatform Academy w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 3 z 4.

Ile czasu zajmuje lekcja „Mapowanie błędów na komunikaty interfejsu”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Kotlin Multiplatform Academy?

Tak. Każda lekcja Kotlin Multiplatform Academy zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Typ wyniku sealed
  2. Przechwytywanie błędów sieci i parsowania
  3. Mapowanie błędów na komunikaty interfejsu
  4. Ponawianie prób i tryb offline
← Powrót do Kotlin Multiplatform Academy