diff --git a/sandwich/src/commonMain/kotlin/com/skydoves/sandwich/ResponseTransformer.kt b/sandwich/src/commonMain/kotlin/com/skydoves/sandwich/ResponseTransformer.kt index 5d7f43f..678e8fe 100644 --- a/sandwich/src/commonMain/kotlin/com/skydoves/sandwich/ResponseTransformer.kt +++ b/sandwich/src/commonMain/kotlin/com/skydoves/sandwich/ResponseTransformer.kt @@ -80,15 +80,18 @@ public inline fun ApiResponse.getOrElse(defaultValue: () -> T): T { } /** - * @author skydoves (Jaewoong Eum) - * - * Returns the encapsulated data if this instance represents [ApiResponse.Success] or - * throws the encapsulated Throwable exception if it is [ApiResponse.Failure.Error] or [ApiResponse.Failure.Exception]. - * - * @throws RuntimeException if it is [ApiResponse.Failure.Error] or - * the encapsulated Throwable exception if it is [ApiResponse.Failure.Exception.throwable] - * - * @return The encapsulated data. + * Retrieves the data from the ApiResponse or throws an exception. + * + * @return the data if ApiResponse is successful + * @throws RuntimeException if ApiResponse is a failure with an error message + * @throws Throwable if ApiResponse is a failure with an exception + * + * Example: + * ``` + * val response: ApiResponse = ApiResponse.Success("Hello, World!") + * val data: String = response.getOrThrow() + * println(data) // Output: Hello, World! + * ``` */ public fun ApiResponse.getOrThrow(): T { when (this) {