Skip to content

davidHarush/RetrofitSafeCallUtil

Repository files navigation

RetrofitSafeCallUtil

For retrofit error handling

the try catch(to retrofit service) will called from the RetrofitSafeCallUtil and you will get a data class Which contains the result, error(in case there is one), and status of the retrofit request

GitHub release (latest by date) GitHub top language GitHub repo size GitHub issues CodeFactor

You need to call
SafeCall.fetch { <retrofit2.Response<T>> }
For example

val request = SafeCall.fetch { api.getPopularMovies() }
if (request.failed || !request.isSuccessful) {
	//  do failed action
} else{
	//  do isSuccessful action
}
        

This return SafeResponse

data class SafeResponse<T>(
    val status: Status,
    val data: Response<T>?,
    val exception: Exception?
)

Dependency

Add it in your root build.gradle at the end of repositories:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

Step 2. Add the dependency

dependencies {
        implementation 'com.github.davidHarush:RetrofitSafeCallUtil:1.1'
}

For more info :

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages