Skip to content

Commit

Permalink
Fix timeout handling
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Feb 14, 2023
1 parent d3b3455 commit e66aa7d
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions dom/src/main/scala/org/http4s/dom/FetchClient.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,19 +98,15 @@ private[dom] object FetchClient {
mergedOptions.referrerPolicy.foreach(init.referrerPolicy = _)

val fetch =
poll(F.fromPromise(F.delay(Fetch.fetch(req.uri.renderString, init))))
F.fromPromise(F.delay(Fetch.fetch(req.uri.renderString, init)))
.onCancel(F.delay(abortController.abort()))

requestTimeout match {
case d: FiniteDuration =>
fetch.timeoutTo(
d,
.timeoutTo(
requestTimeout,
F.raiseError[FetchResponse](new TimeoutException(
s"Request to ${req.uri.renderString} timed out after ${d.toMillis} ms"))
s"Request to ${req.uri.renderString} timed out after ${requestTimeout.toMillis} ms"))
)
case _ =>
fetch
}

poll(fetch)
}
} {
case (r, exitCase) =>
Expand Down

0 comments on commit e66aa7d

Please sign in to comment.