Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Clean Code with Kotlin by Magda Miu - Functions 1 - Clean Code
fun parseProduct(response: Response?) = when (response?.code()){
null -> throw ClientException("Response is null")
200, 201 -> mapToDTO(response.body())
in 400..499 -> throw ClientException("Invalid request")
in 500..599 -> throw ClientException("Server error")
else -> throw ClientException("Error ${response.code()}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment