From e66aa7d1ed8c6b6ad236c88d1894db9477d2a910 Mon Sep 17 00:00:00 2001 From: Arman Bilge Date: Tue, 14 Feb 2023 20:16:42 +0000 Subject: [PATCH] Fix timeout handling --- .../main/scala/org/http4s/dom/FetchClient.scala | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/dom/src/main/scala/org/http4s/dom/FetchClient.scala b/dom/src/main/scala/org/http4s/dom/FetchClient.scala index 3e195a81..9f74143f 100644 --- a/dom/src/main/scala/org/http4s/dom/FetchClient.scala +++ b/dom/src/main/scala/org/http4s/dom/FetchClient.scala @@ -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) =>