T
- Type returned if the request was a success.public static class App.Result<T> extends Object
App.Callback
Modifier and Type | Method and Description |
---|---|
T |
get()
Returns the response in case the request was a success.
|
AppException |
getError()
Returns the error in case of a failed request.
|
T |
getOrDefault(T defaultValue)
Returns the response if the request was a success.
|
T |
getOrThrow()
If the request was successful the response is returned, otherwise the provided error
is thrown.
|
boolean |
isSuccess()
Returns whether or not request was successful
|
static <T> App.Result<T> |
success()
Creates a successful request result with no return value.
|
static <T> App.Result<T> |
withError(AppException exception)
Creates a failed request result.
|
static <T> App.Result<T> |
withResult(T result)
Creates a successful request result with a return value.
|
public static <T> App.Result<T> success()
public static <T> App.Result<T> withResult(T result)
result
- the result value.public static <T> App.Result<T> withError(AppException exception)
exception
- error that occurred.public boolean isSuccess()
true
if the request was a success, false
if not.public T get()
public T getOrDefault(T defaultValue)
public T getOrThrow()
AppException
- provided error in case the request failed.public AppException getError()
AppException
in case of a failed request.