Skip to content

Instantly share code, notes, and snippets.

@magdamiu
Created August 21, 2021 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save magdamiu/199b28616d63fcaab93415b19192d1ff to your computer and use it in GitHub Desktop.
Save magdamiu/199b28616d63fcaab93415b19192d1ff to your computer and use it in GitHub Desktop.
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