Created
August 21, 2021 12:46
-
-
Save magdamiu/199b28616d63fcaab93415b19192d1ff to your computer and use it in GitHub Desktop.
Clean Code with Kotlin by Magda Miu - Functions 1 - Unclean Code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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