Skip to content

Instantly share code, notes, and snippets.

@skydoves
Created April 7, 2022 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skydoves/aefe1b41570bb3e86ef5b5fd2e02e0b7 to your computer and use it in GitHub Desktop.
Save skydoves/aefe1b41570bb3e86ef5b5fd2e02e0b7 to your computer and use it in GitHub Desktop.
retrofit_call_example
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