I have the following retrying logic to retry only when a http call gets a 429. The retry happens in an unintuitive way: instead of calling the whole retryableRequest functions, it only calls the mapResponse. Onlyresp <- mapResponse(sttpResp, sttpResp.body.merge) is being used in the for comprehension of the retryable function, which is the one capturing the failure from mapResponse. Is this a normal behavior? private[databricksapi] def sendRequest(request: SttpRequest[Either[String, String], Any]): ZIO[SttpBackend[Task, Any], Throwable, Response] = for { client <- ZIO.service[SttpBackend[Task, Any]] resp <- retryableRequest(request, client).retryN(5) } yield resp private def retryableRequest(request: SttpRequest[Either[String, String], Any], client: SttpBackend[Task, Any]): ZIO[SttpBackend[Task, Any], Throwable, Response] = for { sttpResp <- client.send(request) resp <- mapResponse(sttpResp, sttpResp.body.merge) } yield resp private def mapResponse(response: SttpResponse[Either[String, String]], body: String) = if (response.code.code == 429) ZIO.fail(new RuntimeException("too many requests")) else ZIO.succeed( Response( status = Status.fromHttpResponseStatus(HttpResponseStatus.valueOf(response.code.code)), body = Body.fromCharSequence(body)))
|