``` fun <DTO> IO<DTO>.withToken(restar...
# arrow
p
Copy code
fun <DTO> IO<DTO>.withToken(restart: () -> IO<Dto>): IO<DTO> = handleErrorWith {
    if (it is HttpException && it.code() == 401) {
        restart()
    } else {
        raiseError(it)
    }
}
Copy code
withToken { accessTokenRepository.refreshAccessToken().flatMap { newToken -> someCall(newToken) } }