All Downloads are FREE. Search and download functionalities are using the official Maven repository.

sttp.client3.RetryWhen.scala Maven / Gradle / Ivy

There is a newer version: 3.10.1
Show newest version
package sttp.client3

import sttp.model.Method

object RetryWhen {
  def isBodyRetryable(body: RequestBody[_]): Boolean = {
    body match {
      case NoBody               => true
      case _: StringBody        => true
      case _: ByteArrayBody     => true
      case _: ByteBufferBody    => true
      case _: InputStreamBody   => false
      case _: FileBody          => true
      case StreamBody(_)        => false
      case MultipartBody(parts) => parts.forall(p => isBodyRetryable(p.body))
    }
  }

  val Default: RetryWhen = {
    case (_, Left(_: SttpClientException.ConnectException)) => true
    case (_, Left(_))                                       => false
    case (request, Right(response)) =>
      isBodyRetryable(request.body) && Method.isIdempotent(request.method) && response.code.isServerError
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy