Skip to content

Commit

Permalink
chore: separate client & server error loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitFicus committed Jan 18, 2025
1 parent 5664283 commit 748ee52
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions app/fr/maif/izanami/errors/IzanamiHttpErrorHandler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class IzanamiHttpErrorHandler(env: Env) extends HttpErrorHandler {

implicit val ec: ExecutionContext = env.executionContext

lazy val logger = Logger("izanami-error-handler")
lazy val clientErrorLogger = Logger("izanami-client-error-handler")
lazy val serverErrorLogger = Logger("izanami-seerver-error-handler")

override def onClientError(request: mvc.RequestHeader, statusCode: Int, message: String): Future[Result] = {
val uuid =
Expand All @@ -25,15 +26,15 @@ class IzanamiHttpErrorHandler(env: Env) extends HttpErrorHandler {
val errorMessage =
s"Client Error [$uuid]: $msg on ${request.uri} ($statusCode)"

logger.error(errorMessage)
clientErrorLogger.error(errorMessage)
Future.successful(Status(statusCode)(Json.obj("message" -> msg)))
}

override def onServerError(request: mvc.RequestHeader, exception: Throwable): Future[Result] = {
val uuid =
java.util.UUID.nameUUIDFromBytes(new SecureRandom().generateSeed(16))

logger.error(
serverErrorLogger.error(
s"Server Error [$uuid]: ${exception.getMessage} on ${request.uri}",
exception)
Future.successful(Status(INTERNAL_SERVER_ERROR)(Json.obj("message" -> exception.getMessage)).withHeaders(("content-type", "application/json")))
Expand Down

0 comments on commit 748ee52

Please sign in to comment.