-
-
Save skydoves/aefe1b41570bb3e86ef5b5fd2e02e0b7 to your computer and use it in GitHub Desktop.
retrofit_call_example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface PosterService { | |
@GET("DisneyPosters.json") | |
suspend fun fetchPosters(): List<Poster> | |
} | |
class PosterRemoteDataSource( | |
private val posterService: PosterService | |
) { | |
suspend operator fun invoke(): List<Poster> = try { | |
posterService.fetchPosters() | |
} catch (e: HttpException) { | |
// error handling | |
emptyList() | |
} catch (e: Throwable) { | |
// error handling | |
emptyList() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment