From f0195db3fb00c59734c372c562592ed788a3c771 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Raddum=20Berg?= Date: Wed, 13 Jul 2022 13:34:29 +0200 Subject: [PATCH] http status codes as exceptions, naturally --- .../scalablytyped/converter/internal/RunCache.scala | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/RunCache.scala b/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/RunCache.scala index e9c8803c12..938245eb0a 100644 --- a/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/RunCache.scala +++ b/sbt-converter/src/main/scala/org/scalablytyped/converter/internal/RunCache.scala @@ -265,14 +265,9 @@ object RunCache { private def getUrl(uri: URI)(implicit ec: ExecutionContext): Future[PresentFile] = http.run(Request(uri.toString)).transform { - case Success(response) => - val res = response.status match { - case success if success > 199 && success < 300 => PresentFile.Downloaded(response.bodyAsByteBuffer.array()) - case 404 => PresentFile.NotFound - case 403 => PresentFile.Forbidden - case other => PresentFile.Err(new RuntimeException(s"Got status code $other")) - } - Success(res) + case Success(response) => Success(PresentFile.Downloaded(response.bodyAsByteBuffer.array())) + case Failure(x: gigahorse.StatusError) if x.status == 404 => Success(PresentFile.NotFound) + case Failure(x: gigahorse.StatusError) if x.status == 403 => Success(PresentFile.Forbidden) case Failure(th) => Success(PresentFile.Err(th)) } }