Skip to content

Commit

Permalink
Merge pull request #581 from phdoerfler/main
Browse files Browse the repository at this point in the history
Added stack trace printing
  • Loading branch information
milessabin authored Mar 15, 2024
2 parents fa42e36 + 536dc0d commit 4c8740e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions demo/src/main/scala/demo/DemoServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ import cats.effect.IO
import cats.effect.Resource
import cats.syntax.all._
import com.comcast.ip4s._
import org.http4s.HttpRoutes
import org.http4s.{HttpApp, HttpRoutes}
import org.http4s.ember.server.EmberServerBuilder
import org.http4s.server.middleware.Logger
import org.http4s.server.middleware.{ErrorAction, ErrorHandling, Logger}
import org.http4s.server.staticcontent.resourceServiceBuilder

// #server
Expand All @@ -36,12 +36,21 @@ object DemoServer {

val httpApp = Logger.httpApp(true, false)(httpApp0)

val withErrorLogging: HttpApp[IO] = ErrorHandling.Recover.total(
ErrorAction.log(
httpApp,
messageFailureLogAction = errorHandler,
serviceErrorLogAction = errorHandler))

// Spin up the server ...
EmberServerBuilder.default[IO]
.withHost(ip"0.0.0.0")
.withPort(port"8080")
.withHttpApp(httpApp)
.withHttpApp(withErrorLogging)
.build.void
}

def errorHandler(t: Throwable, msg: => String) : IO[Unit] =
IO.println(msg) >> IO.println(t) >> IO.println(t.printStackTrace())
}
// #server

0 comments on commit 4c8740e

Please sign in to comment.