suspendOnError

inline suspend fun <T> ApiResponse<T>.suspendOnError(crossinline onResult: suspend ApiResponse.Failure.Error<T>.() -> Unit): ApiResponse<T>

Author

skydoves (Jaewoong Eum)

A suspension scope function that would be executed for handling error responses if the request failed.

Return

The original ApiResponse.

Parameters

onResult

The receiver function that receiving ApiResponse.Failure.Exception if the request failed.


inline suspend fun <T, V> ApiResponse<T>.suspendOnError(mapper: ApiErrorModelMapper<V>, crossinline onResult: suspend V.() -> Unit): ApiResponse<T>

Author

skydoves (Jaewoong Eum)

A suspension scope function that would be executed for handling error responses if the request failed with a ApiErrorModelMapper. This function receives a ApiErrorModelMapper and returns the mapped result into the scope.

Return

The original ApiResponse.

Parameters

mapper

The ApiErrorModelMapper for mapping ApiResponse.Failure.Error response as a custom V instance model.

onResult

The receiver function that receiving ApiResponse.Failure.Exception if the request failed.