Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Penify]: Documentation for commit - e3ed592 #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,18 @@ public inline fun <T> ApiResponse<T>.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<String> = ApiResponse.Success("Hello, World!")
* val data: String = response.getOrThrow()
* println(data) // Output: Hello, World!
* ```
*/
public fun <T> ApiResponse<T>.getOrThrow(): T {
when (this) {
Expand Down
Loading