首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在http4s中记录InternalServerError上的请求url

在http4s中记录InternalServerError上的请求url
EN

Stack Overflow用户
提问于 2020-11-23 19:18:52
回答 1查看 181关注 0票数 1

如果发生未处理的错误,则http4s返回InternalServerError。当InternalServerError发生时,是否可以记录请求的url?如果是,最好的方法是什么?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-23 19:52:05

它不是开箱即用吗?

以下是来自快速入门指南https://http4s.org/v0.21/的g8模板项目的日志,其中添加了抛出运行时异常的路由:

代码语言:javascript
复制
[ioapp-compute-1] INFO  o.h.s.m.Logger - HTTP/1.1 GET /bad_joke Headers(Accept: */*, Cache-Control: no-cache, Host: localhost:8089, Connection: Keep-Alive, User-Agent: Apache-HttpClient/4.5.12 (Java/11.0.8), Accept-Encoding: gzip,deflate) body="" 
[ioapp-compute-1] INFO  o.h.s.m.Logger - service raised an error: class java.lang.RuntimeException 
[ioapp-compute-1] ERROR o.h.s.service-errors - Error servicing request: GET /bad_joke from 127.0.0.1 
java.lang.RuntimeException: haha
        at pack.H4sRoutes$$anonfun$jokeRoutes$1.applyOrElse(H4sRoutes.scala:19)
        at pack.H4sRoutes$$anonfun$jokeRoutes$1.applyOrElse(H4sRoutes.scala:13)
        at $anonfun$combineK$1 @ org.http4s.syntax.KleisliResponseOps.$anonfun$orNotFound$1(KleisliSyntax.scala:38)
        at getOrElse @ org.http4s.syntax.KleisliResponseOps.$anonfun$orNotFound$1(KleisliSyntax.scala:38)
        at guaranteeCase$extension @ org.http4s.server.middleware.RequestLogger$.$anonfun$impl$9(RequestLogger.scala:97)
        at map @ org.http4s.server.middleware.RequestLogger$.$anonfun$impl$9(RequestLogger.scala:101)
        at flatMap @ org.http4s.server.middleware.RequestLogger$.$anonfun$impl$7(RequestLogger.scala:82)
        at flatMap @ org.http4s.server.middleware.ResponseLogger$.$anonfun$impl$7(ResponseLogger.scala:65)
        at guaranteeCase$extension @ org.http4s.server.middleware.ResponseLogger$.$anonfun$impl$7(ResponseLogger.scala:88)
        at main$ @ pack.Main$.main(Main.scala:5)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64967413

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档