Skip to content

Instantly share code, notes, and snippets.

@davidbilik
Created June 28, 2018 14:04
Show Gist options
  • Save davidbilik/b4b11f66358971642fe639abd6d086fe to your computer and use it in GitHub Desktop.
Save davidbilik/b4b11f66358971642fe639abd6d086fe to your computer and use it in GitHub Desktop.
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