R.Chatsiri
R.Chatsiri

Reputation: 107

How to handle "Action not found" with Dependency Injection Play framework 2.4

I override class HttpErrorHandler on Injection Dependency concept and try to handles routing page. I don't need the Action not found page presented when routing page of URL incorrect,but it must to presented by specify page route on view.html.error.notFoundPage() of HttpPageErrorHandler. Figure such as below when try to access URL didn't included with parameter

http://localhost:9000/adminlanding

Routing page assigned as

GET /adminlanding/:userId/:ip/:dateFound/ controllers.DashboardAdmin.landing(userId: String, ip : String, dateFound : String)

HttpPageErrorHandler handles 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 declares configuration to call injection class

play.http.HttpErrorHandler = RequestHandler

After run command line with sbt run stills show Action not found page.

Upvotes: 1

Views: 700

Answers (1)

amer
amer

Reputation: 1672

how about

play.http.errorHandler = "global.HttpPageErrorHandler"

or whatever is your package .

Upvotes: 1

Related Questions