Skip to content

Commit

Permalink
workaround scalac bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
jdegoes committed Jul 21, 2023
1 parent 6a1df52 commit 2589483
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
1 change: 0 additions & 1 deletion zio-http/src/main/scala/zio/http/Response.scala
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ object Response {
case _: IllegalAccessError => error(Status.Forbidden, throwable.getMessage)
case _: NotDirectoryException => error(Status.BadRequest, throwable.getMessage)
case _: IllegalArgumentException => error(Status.BadRequest, throwable.getMessage)
case _: IllegalFormatException => error(Status.BadRequest, throwable.getMessage)
case _: java.io.FileNotFoundException => error(Status.NotFound, throwable.getMessage)
case _: java.net.ConnectException => error(Status.ServiceUnavailable, throwable.getMessage)
case _: java.net.SocketTimeoutException => error(Status.GatewayTimeout, throwable.getMessage)
Expand Down
6 changes: 4 additions & 2 deletions zio-http/src/test/scala/zio/http/HttpAppSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,22 @@ import zio.test.Assertion._
import zio.test._

object HttpAppSpec extends ZIOSpecDefault {
def extractStatus(response: Response): Status = response.status

def spec = suite("HttpAppSpec")(
test("empty not found") {
val app = HttpApp.empty

for {
result <- app.run()
} yield assertTrue(result.status == Status.NotFound)
} yield assertTrue(extractStatus(result) == Status.NotFound)
},
test("compose empty not found") {
val app = HttpApp.empty ++ HttpApp.empty

for {
result <- app.run()
} yield assertTrue(result.status == Status.NotFound)
} yield assertTrue(extractStatus(result) == Status.NotFound)
},
test("run identity") {
val body = Body.fromString("foo")
Expand Down
8 changes: 4 additions & 4 deletions zio-http/src/test/scala/zio/http/ResponseSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ object ResponseSpec extends ZIOSpecDefault {
test("from IllegalArgumentException") {
val cause = Cause.fail(new IllegalArgumentException)

assertTrue(Response.fromCause(cause).status == Status.BadRequest)
assertTrue(extractStatus(Response.fromCause(cause)) == Status.BadRequest)
},
test("from String") {
val cause = Cause.fail("error")

assertTrue(Response.fromCause(cause).status == Status.InternalServerError)
assertTrue(extractStatus(Response.fromCause(cause)) == Status.InternalServerError)
},
),
suite("fromThrowable")(
test("from Throwable") {
assertTrue(Response.fromThrowable(new Throwable).status == Status.InternalServerError)
assertTrue(extractStatus(Response.fromThrowable(new Throwable)) == Status.InternalServerError)
},
test("from IllegalArgumentException") {
assertTrue(Response.fromThrowable(new IllegalArgumentException).status == Status.BadRequest)
assertTrue(extractStatus(Response.fromThrowable(new IllegalArgumentException)) == Status.BadRequest)
},
),
suite("redirect")(
Expand Down
6 changes: 4 additions & 2 deletions zio-http/src/test/scala/zio/http/RouteSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import zio._
import zio.test._

object RouteSpec extends ZIOSpecDefault {
def extractStatus(response: Response): Status = response.status

def spec = suite("RouteSpec")(
suite("Route#sandbox")(
test("infallible route does not change under sandbox") {
Expand All @@ -32,7 +34,7 @@ object RouteSpec extends ZIOSpecDefault {

for {
result <- ignored.toHandler.run().merge
} yield assertTrue(result.status == Status.Ok)
} yield assertTrue(extractStatus(result) == Status.Ok)
},
test("route dying with throwable ends in internal server error") {
val route =
Expand All @@ -43,7 +45,7 @@ object RouteSpec extends ZIOSpecDefault {

for {
result <- ignored.toHandler.merge.run()
} yield assertTrue(result.status == Status.InternalServerError)
} yield assertTrue(extractStatus(result) == Status.InternalServerError)
},
),
suite("auto-sandboxing for middleware")(
Expand Down

0 comments on commit 2589483

Please sign in to comment.