Skip to content

Commit

Permalink
fix: maybe scala
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Dec 3, 2024
1 parent 4a01d55 commit 7aca9b3
Showing 1 changed file with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,24 +78,28 @@ abstract class ApiClient(
defaultConnectTimeout: Duration,
defaultWriteTimeout: Duration
): Requester = {
val optionsWithDefaultTimeouts = options.copy(
readTimeout = defaultReadTimeout,
connectTimeout = defaultConnectTimeout,
writeTimeout = defaultWriteTimeout
)

val algoliaAgent = AlgoliaAgent(BuildInfo.version)
.addSegment(AgentSegment(clientName, Some(BuildInfo.version)))
.addSegments(options.agentSegments)
.addSegments(optionsWithDefaultTimeouts.agentSegments)

val hosts = if (options.hosts.isEmpty) defaultHosts else options.hosts
val hosts = if (optionsWithDefaultTimeouts.hosts.isEmpty) defaultHosts else optionsWithDefaultTimeouts.hosts
val statefulHosts = hosts.map(host => StatefulHost(host)).toList

options.withReadTimeout(Option(options.readTimeout).getOrElse(defaultReadTimeout)).withWriteTimeout(Option(options.writeTimeout).getOrElse(defaultWriteTimeout)).withConnectTimeout(Option(options.connectTimeout).getOrElse(defaultConnectTimeout))


val builder = HttpRequester
.builder(options.customFormats.getOrElse(formats))
.builder(optionsWithDefaultTimeouts.customFormats.getOrElse(formats))
.withInterceptor(authInterceptor)
.withInterceptor(new UserAgentInterceptor(algoliaAgent))
.withInterceptor(new RetryStrategy(statefulHosts))

options.requesterConfig.foreach(_(builder))
optionsWithDefaultTimeouts.requesterConfig.foreach(_(builder))

builder.build(options)
builder.build(optionsWithDefaultTimeouts)
}

/** Executes the given request and returns the response.
Expand Down

0 comments on commit 7aca9b3

Please sign in to comment.