Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
/zioPublic

unexpected behavior ZIO retry#7657

Unanswered
fernanluyano asked this question inQ&A
Discussion options

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)))
You must be logged in to vote

Replies: 0 comments

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Q&A
Labels
None yet
1 participant
@fernanluyano

[8]ページ先頭

©2009-2025 Movatter.jp