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 - Unclean Code
fun parseProduct(response: Response?): Product? {
if (response == null) {
throw ClientException("Response is null")
}
val code: Int = response.code()
if (code == 200 || code == 201) {
return mapToDTO(response.body())
}
if (code >= 400 && code <= 499) {
throw ClientException("Invalid request")
}
if (code >= 500 && code <= 599) {
throw ClientException("Server error")
}
throw ClientException("Error $code")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment