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/ccc1fb713782dc6989b9cdd468539f6e to your computer and use it in GitHub Desktop.
Save magdamiu/ccc1fb713782dc6989b9cdd468539f6e to your computer and use it in GitHub Desktop.
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