Skip to content

The SDK does not handle error conditions properly #1539

@haywood

Description

@haywood
  1. The SDKErrorResponse type does not provide explicit access to the HTTP status code or other standard metadata
  2. The ok() function throws java.lang.Error, which should not be thrown by JVM application code
  3. 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!!")
    }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions