sdk-codegen icon indicating copy to clipboard operation
sdk-codegen copied to clipboard

Raise full error for bad responses in Kotlin SDK

Open tjbanghart opened this issue 1 year ago • 0 comments

We are missing helpful errors in the ok helper method.

We should turn this

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!!")
    }
}

into

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
        is SDKResponse.SDKError -> throw Error(response.message)
        else -> throw Error(response.toString())
    }
}

tjbanghart avatar Dec 12 '23 18:12 tjbanghart