update app exception

This commit is contained in:
PranshulGG committed 2026-08-15 16:07:03 +05:30
1 parent da373ba486
commit a959cd93c4
1 file changed
+9
@@ -5,6 +5,7 @@ import com.pranshulgg.weather_master_app.R
import java.io.IOException
import java.net.SocketTimeoutException
import java.net.UnknownHostException
import javax.net.ssl.SSLHandshakeException
import kotlin.coroutines.cancellation.CancellationException
sealed class AppException(message: String? = null) : Exception(message) {
@@ -15,6 +16,8 @@ sealed class AppException(message: String? = null) : Exception(message) {
class NoApiKeyError : AppException()
class SecureConnection : AppException()
}
fun AppException.toMessageRes(): Int {
@@ -24,6 +27,8 @@ fun AppException.toMessageRes(): Int {
is AppException.Server -> R.string.error_server
is AppException.Unknown -> R.string.error_generic
is AppException.NoApiKeyError -> R.string.error_no_api_key
is AppException.SecureConnection -> R.string.error_secure_connection_failed
}
}
@@ -32,10 +37,14 @@ fun Throwable.toAppException(): AppException {
return when (this) {
is AppException -> this
is SSLHandshakeException -> AppException.SecureConnection()
is UnknownHostException,
is SocketTimeoutException,
is IOException -> AppException.Network()
is HttpException -> AppException.Server()