0

I am attempting to load a custom error handler in Play Framework (2.6) as per the documentation but am receiving the following error message -

Cannot load play.http.errorHandler

Custom error handler (app/services/ErrorHandler)

   package services

   import javax.inject.Singleton
   import play.api.http.HttpErrorHandler
   import play.api.mvc.Results._
   import play.api.mvc._

   import scala.concurrent._

   @Singleton
   class ErrorHandler extends HttpErrorHandler {

     def onClientError(request: RequestHeader, statusCode: Int, message: String) = {
       Future.successful(
         Status(statusCode)(
           message
         )
       )
     }

     def onServerError(request: RequestHeader, exception: Throwable) = {
       Future.successful(
         InternalServerError("A server errors occurred: " + exception.getMessage)
       )
     }
   }

application.conf

   play.http.errorHandler = "com.mySite.services.ErrorHandler"

1 Answers1

0

In your code, the package isn't com.mySite.services. It's just services.

application.conf

play.http.errorHandler = "services.ErrorHandler"
ejisan
  • 111
  • 4
  • Thanks. Caught this earlier today and was about to post. Discovered it's a nightmare to render a page in `onClientError` rather than a simple `String` message. Easy if just rendering the view, e.g. `views.html.myTemplate(title)` but not so if building the page via actions_ – jesus g_force Harris Oct 23 '19 at 16:12