Created
June 28, 2018 14:04
-
-
Save davidbilik/b4b11f66358971642fe639abd6d086fe to your computer and use it in GitHub Desktop.
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
class Repository(val api: Api) { | |
fun login(email: String, password: String): Single<User> { | |
return api.login(email, password) | |
.mapApiExceptions { | |
when (it.code()) { | |
401 -> InvalidCredentialsException() | |
400 -> { | |
val errorResponse: ValidationErrorResponse = it.bodyToValidationError() | |
ValidationException(errorResponse.fields.groupBy({ it.error }, { it.field })) | |
} | |
else -> null | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment