gpt4 book ai didi

error-handling - 如何使用依赖注入(inject) Play Framework 2.4 处理 "Action not found"

转载 作者:行者123 更新时间:2023-12-03 07:54:08 24 4
gpt4 key购买 nike

我覆盖类 HttpErrorHandler关于注入(inject)依赖概念并尝试处理路由页面。我不需要 Action not found URL的路由页面错误时显示的页面,但必须通过view.html.error.notFoundPage()上的指定页面路由来呈现的 HttpPageErrorHandler .如下图,当尝试访问 URL 时未包含在参数中
http://localhost:9000/adminlanding
路由页面分配为
GET /adminlanding/:userId/:ip/:dateFound/ controllers.DashboardAdmin.landing(userId: String, ip : String, dateFound : String)
HttpPageErrorHandler 处理 Action not found

class HttpPageErrorHandler @Inject() (router: Router) extends HttpErrorHandler {
private def errorHandler = Play.maybeApplication.fold[HttpErrorHandler](DefaultHttpErrorHandler)(_.errorHandler)

def onClientError(request: RequestHeader, statusCode: Int, message: String) : Future[Result]= {
statusCode match {
case Status.NOT_FOUND =>
Future.successful(NotFound(views.html.errors.notFoundPage(request)))
case clientError if statusCode >= 400 && statusCode < 500 =>
Future.successful(Forbidden(views.html.errors.notFoundPage(request)))
}
}

def onServerError(request: RequestHeader, exception: Throwable): Future[Result] = {
errorHandler.onServerError(request, exception)
}

}

Application.conf 声明配置调用注入(inject)类
play.http.HttpErrorHandler = RequestHandler
使用 sbt run 运行命令行后剧照展示 Action not found页。

最佳答案

怎么样

play.http.errorHandler = "global.HttpPageErrorHandler"

或者你的包裹是什么。

关于error-handling - 如何使用依赖注入(inject) Play Framework 2.4 处理 "Action not found",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32926127/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com