-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3259b0
commit c2e6d48
Showing
3 changed files
with
37 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package lila.fishnet | ||
package http | ||
|
||
import cats.data.Kleisli | ||
import cats.syntax.all.* | ||
import cats.effect.IO | ||
import org.http4s.internal.Logger as Http4sLogger | ||
import org.http4s.{ HttpApp, Response } | ||
import org.typelevel.log4cats.Logger | ||
|
||
object ApiErrorLogger: | ||
|
||
def logOnError: Response[IO] => Boolean = res => !res.status.isSuccess && res.status.code != 404 | ||
def instance(using Logger[IO]): HttpApp[IO] => HttpApp[IO] = http => | ||
Kleisli: req => | ||
http(req).flatTap: res => | ||
logOnError(res) | ||
.pure[IO] | ||
.ifM( | ||
Http4sLogger.logMessage[IO](res)(logHeaders = true, logBody = true)(Logger[IO].warn), | ||
IO.unit | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters