Google berkomitmen untuk mendorong terwujudnya keadilan ras bagi komunitas Kulit Hitam. Lihat caranya.

Error

data class Error<Key : Any, Value : Any> : PagingSource.LoadResult<Key, Value>
kotlin.Any
   ↳ androidx.paging.PagingSource.LoadResult<Key, Value>
   ↳ androidx.paging.PagingSource.LoadResult.Error

Error result object for PagingSource.load.

This return type indicates an expected, recoverable error (such as a network load failure). This failure will be forwarded to the UI as a LoadState.Error, and may be retried.


/**
 * Sample Page-Keyed PagingSource, which uses String tokens to load pages.
 *
 * Loads Items from network requests via Retrofit to a backend service.
 */
class MyPagingSource(
    val myBackend: MyBackendService
) : PagingSource<String, Item>() {
    override suspend fun load(params: LoadParams<String>): LoadResult<String, Item> {
        // Retrofit calls that return the body type throw either IOException for network
        // failures, or HttpException for any non-2xx HTTP status codes. This code reports all
        // errors to the UI, but you can inspect/wrap the exceptions to provide more context.
        return try {
            // Suspending network load via Retrofit. This doesn't need to be wrapped in a
            // withContext(Dispatcher.IO) { ... } block since Retrofit's Coroutine
            // CallAdapter dispatches on a worker thread.
            val response = myBackend.searchItems(params.key)
            LoadResult.Page(
                data = response.items,
                prevKey = response.prev,
                nextKey = response.next
            )
        } catch (e: IOException) {
            LoadResult.Error(e)
        } catch (e: HttpException) {
            LoadResult.Error(e)
        }
    }
}

Summary

Public constructors
<init>(throwable: Throwable)

Error result object for PagingSource.load.

Properties
Throwable

Public constructors

<init>

Error(throwable: Throwable)

Error result object for PagingSource.load.

This return type indicates an expected, recoverable error (such as a network load failure). This failure will be forwarded to the UI as a LoadState.Error, and may be retried.


/**
 * Sample Page-Keyed PagingSource, which uses String tokens to load pages.
 *
 * Loads Items from network requests via Retrofit to a backend service.
 */
class MyPagingSource(
    val myBackend: MyBackendService
) : PagingSource<String, Item>() {
    override suspend fun load(params: LoadParams<String>): LoadResult<String, Item> {
        // Retrofit calls that return the body type throw either IOException for network
        // failures, or HttpException for any non-2xx HTTP status codes. This code reports all
        // errors to the UI, but you can inspect/wrap the exceptions to provide more context.
        return try {
            // Suspending network load via Retrofit. This doesn't need to be wrapped in a
            // withContext(Dispatcher.IO) { ... } block since Retrofit's Coroutine
            // CallAdapter dispatches on a worker thread.
            val response = myBackend.searchItems(params.key)
            LoadResult.Page(
                data = response.items,
                prevKey = response.prev,
                nextKey = response.next
            )
        } catch (e: IOException) {
            LoadResult.Error(e)
        } catch (e: HttpException) {
            LoadResult.Error(e)
        }
    }
}

Properties

throwable

val throwable: Throwable