package de.trainingstagebuch.app.utils

import de.trainingstagebuch.app.core.StandardErrorMapper

object AppErrorUtils {
    fun unknown(): String {
        return StandardErrorMapper.fromRes(de.trainingstagebuch.app.R.string.error_unknown)
    }

    fun fromThrowable(throwable: Throwable): String {
        return StandardErrorMapper.map(throwable).message
    }

    fun backendOrThrowable(
        backendMessage: String?,
        throwable: Throwable
    ): String {
        val normalizedBackend = backendMessage?.trim().orEmpty()
        if (normalizedBackend.isNotBlank()) return normalizedBackend
        return fromThrowable(throwable)
    }
}
