-
Notifications
You must be signed in to change notification settings - Fork 199
Labels
Description
- The
SDKErrorResponse
type does not provide explicit access to the HTTP status code or other standard metadata - The
ok()
function throws java.lang.Error, which should not be thrown by JVM application code - The
ok()
function does not chain the cause of a client-side exception or include its error message
Source of the SDKErrorResponse class for convenience:
/** An erroring SDK call. */
data class SDKErrorResponse<T>(
/** The error object returned by the SDK call. */
val value: T,
) : SDKResponse() {
/** Whether the SDK call was successful. */
val ok: Boolean = false
}
Source of the ok function for convenience
/**
* Response handler that throws an error on error response, returns success result on success
*/
fun <T>fun <T> ok(response: SDKResponse): T {
@Suppress("UNCHECKED_CAST")
when (response) {
is SDKResponse.SDKErrorResponse<*> -> throw Error(response.value.toString())
is SDKResponse.SDKSuccessResponse<*> -> return response.value as T
else -> throw Error("Fail!!")
}
}