Skip to content

Commit

Permalink
jsdomClient: don't parse unsuccessful http response bodies, throw sta…
Browse files Browse the repository at this point in the history
…tus instead
  • Loading branch information
fdietze authored Aug 24, 2024
1 parent a04d05d commit edd2ee5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions jsdomClient/src/main/scala/HttpRpcTransport.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ object HttpRpcTransport {

def apply[F[_]: Async](config: F[HttpRequestConfig]): RequestTransport[String, F] = new RequestTransport[String, F] {
override def apply(request: Request[String]): F[String] = for {
config <- config
url = s"${config.baseUri}/${request.method.traitName}/${request.method.methodName}"
config <- config
url = s"${config.baseUri}/${request.method.traitName}/${request.method.methodName}"
requestArgs = new dom.RequestInit { headers = config.headers.toJSDictionary; method = dom.HttpMethod.POST; body = request.payload }
result <- Async[F].fromThenable(Async[F].delay[js.Thenable[String]](dom.fetch(url, requestArgs).`then`[String](_.text())))
response <- Async[F].fromPromise(Async[F].delay(dom.fetch(url, requestArgs)))
_ <- Async[F].raiseWhen(!response.ok)(new Exception(s"HTTP error ${response.status}"))
result <- Async[F].fromPromise(Async[F].delay(response.text()))
} yield result
}
}

0 comments on commit edd2ee5

Please sign in to comment.