Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ core Public

Core utilities for Android apps - Result types, error handling and mappers

Notifications You must be signed in to change notification settings

Zlurgg/core

Repository files navigation

Core

Core utilities for Android apps - Result types, error handling, and mappers.

Installation

Add GitHub Packages repository to your settings.gradle.kts:

dependencyResolutionManagement {
    repositories {
        google()
        mavenCentral()
        maven {
            url = uri("https://maven.pkg.github.com/Zlurgg/core")
            credentials {
                username = providers.gradleProperty("gpr.user").orNull
                password = providers.gradleProperty("gpr.key").orNull
            }
        }
    }
}

Add dependency to your build.gradle.kts:

dependencies {
    implementation("io.github.zlurgg:core:1.0.0")
}

Authentication

GitHub Packages requires authentication even for public packages. Create a Personal Access Token (PAT) with read:packages scope and add to ~/.gradle/gradle.properties:

gpr.user=YOUR_GITHUB_USERNAME
gpr.key=YOUR_PERSONAL_ACCESS_TOKEN

Contents

Result Type

Type-safe error handling without exceptions:

sealed interface Result<out D, out E : Error> {
    data class Success<out D>(val data: D) : Result<D, Nothing>
    data class Error<out E : io.github.zlurgg.core.domain.error.Error>(val error: E) : Result<Nothing, E>
}

DataError

Typed error hierarchy for local and remote operations:

sealed interface DataError : Error {
    enum class Local : DataError { DISK_FULL, NOT_FOUND, PERMISSION_DENIED, UNKNOWN }
    enum class Remote : DataError { NO_INTERNET, SERVER_ERROR, TIMEOUT, NOT_FOUND, UNKNOWN }
}

ErrorMapper

Maps exceptions to typed DataErrors:

val result = ErrorMapper.safeSuspendCall(TAG) {
    // your code that might throw
}

ErrorFormatter

Converts DataErrors to user-friendly messages:

val message = ErrorFormatter.format(error, "loading data")
// "Unable to loading data: No internet connection"

License

MIT License

About

Core utilities for Android apps - Result types, error handling and mappers

Resources

Stars

Watchers

Forks

Packages

 
 
 

Languages