```fun worksFromDOI(doi: String): Either<Except...
# functional
b
Copy code
fun worksFromDOI(doi: String): Either<Exception, String> {
        return runBlocking {
            // Waiting the necessary delay to respect the rate limit
            delay(calcDelay())

            val call = httpClient.call("$API_URL/works/$doi") {
                method = HttpMethod.Get
            }

            // Updating the delay according to what is contained in the headers
            updateDelayFromHeaderData(
                call.response.headers.get("X-Rate-Limit-Limit"),
                call.response.headers.get("X-Rate-Limit-Interval"))


            lastQueryTime = LocalDateTime.now()
            when (call.response.status.value) {
                200 -> Either.Right(call.response.readText())
                404 -> Either.Left(NonExistingReference())
                else -> Either.Left(UnManagedReturnCode(call.response.status.value))
            }

        }
    }