package com.hermes.app.core.errors

import com.hermes.app.R
import com.hermes.app.core.localization.HermesLocalizationStore
import com.hermes.app.core.network.HermesApiException
import java.io.IOException
import kotlinx.coroutines.CancellationException

fun mapUserFacingError(
    localizationStore: HermesLocalizationStore,
    localeCode: String,
    error: Throwable?,
): String? {
    return when (error) {
        null -> null
        is CancellationException -> null
        is IOException -> localizationStore.string(localeCode, R.string.errors_network)
        is HermesApiException.HttpStatus -> localizationStore.string(localeCode, R.string.errors_generic)
        else -> localizationStore.string(localeCode, R.string.errors_generic)
    }
}
