pakoito
05/09/2019, 8:53 AMfun <DTO> IO<Response<DTO>>.withToken(accessToken: IO<AccessToken>): IO<Response<DTO>> =
fx {
val response = this@withToken.bind()
val unwrapped = response.unwrapBody(IO.applicativeError()).fix()
unwrapped.handleErrorWith { t ->
if (t is HttpException && t.code() == 401) {
accessToken.flatMap { this@withToken.withToken(HEREHEREHEREHERE) }
} else {
raiseError<Response<DTO>>(IllegalArgumentException()).fix()
}
}.fix().bind()
}