RestResult

value class RestResult<out T>(source)

Encapsulates a successful outcome or a failure.

Failures can be dismissed as long as the value isn't retrieved.

See also

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

Returns true if this instance represents a failed outcome. In this case isSuccess returns false.

Link copied to clipboard

Whether this result's exception has been ignored.

Link copied to clipboard

Returns true if this instance represents a successful outcome. In this case isFailure returns false.

Functions

Link copied to clipboard

Returns the encapsulated Throwable exception if this instance represents failure or null if it is success.

Link copied to clipboard

Returns the encapsulated Throwable exception if this instance represents failure or null if it is success or the exception is ignored.

Link copied to clipboard
fun getOrNull(): T?

Returns the encapsulated value if this instance represents success or null if it is failure.

Link copied to clipboard
fun getOrThrow(): T

Returns the encapsulated value if this instance represents success or throws the encapsulated Throwable exception if it is failure.

Link copied to clipboard
inline fun <T> RestResult<T>.handle(vararg types: KClass<out Throwable>, block: (Throwable) -> Unit): RestResult<T>
inline fun <T> RestResult<T>.handle(predicate: (Throwable) -> Boolean, block: (Throwable) -> Unit): RestResult<T>

inline fun <T> RestResult<T>.handle(vararg responses: ErrorResponse, block: (ErrorResponseException) -> Unit): RestResult<T>

Dismisses the encapsulated error response and runs the given block if it corresponds to an ignored response.

Link copied to clipboard
fun <T> RestResult<T>.ignore(vararg types: KClass<out Throwable>): RestResult<T>

Dismisses the encapsulated exception if it corresponds to an ignored exception.

fun <T> RestResult<T>.ignore(vararg responses: ErrorResponse): RestResult<T>

Dismisses the encapsulated error response if it corresponds to an ignored response.

inline fun <T> RestResult<T>.ignore(predicate: (Throwable) -> Boolean): RestResult<T>

Dismisses the encapsulated exception if it corresponds to an predicate.

Link copied to clipboard

Runs the given block if the result is an error response.

Runs the given block if the result is the specified error response.

Link copied to clipboard

Runs the given block if the result is an ErrorResponseException.

Link copied to clipboard
inline fun onFailure(block: (Throwable) -> Unit): RestResult<T>

Runs the given block on the encapsulated Throwable exception if this instance represents failure, and the exception is not ignored.

Link copied to clipboard
inline fun onSuccess(block: (T) -> Unit): RestResult<T>

Runs the given block on the encapsulated value if this instance represents success.

Link copied to clipboard
fun orThrow()

Throws the encapsulated Throwable exception if it is failure and it is not ignored.

Link copied to clipboard
inline fun <T : R, R> RestResult<T>.recover(vararg types: KClass<out Throwable>, block: (Throwable) -> R): RestResult<R>
inline fun <T : R, R> RestResult<T>.recover(predicate: (Throwable) -> Boolean, block: (Throwable) -> R): RestResult<R>

inline fun <T : R, R> RestResult<T>.recover(vararg responses: ErrorResponse, block: (ErrorResponseException) -> R): RestResult<R>

Maps the encapsulated error response using the given function block if it corresponds to an ignored response.

Link copied to clipboard
open override fun toString(): String