Hi, say after send a request , the response have two type ,
when success
@Serializable
data class Success(
var code: Int, // maybe 0
var content: String,
) {}
while fail:
@Serializable
data class Fail(
var code: Int, // maybe 1
var err: String,
) {}
I wanna know what is the elegant way to handle the two situation?
val res:Response = sendRequest<what should I put here?>()
// and how should I define Response?
if(res instanceOf Success){...} else if (res instanceOf Fail){...}
and is the code above a proper way ?