0

I'm using Play in Scala to develop a website. I've added the following line to my application.conf file in order to include the default error handling:

play.http.errorHandler = play.api.http.HtmlOrJsonHttpErrorHandler

I've done this by advice of the official documentation. However, when I add this line I get the following error:

play.api.PlayException: Cannot load play.http.errorHandler[play.http.errorHandler [play.api.http.HtmlOrJsonHttpErrorHandler] was not loaded.]
at play.utils.Reflect$.loadClass$1(Reflect.scala:111)
at play.utils.Reflect$.configuredClass(Reflect.scala:124)
at play.utils.Reflect$.bindingsFromConfiguration(Reflect.scala:50)
at play.api.http.HttpErrorHandler$.bindingsFromConfiguration(HttpErrorHandler.scala:54)
at play.api.inject.BuiltinModule$$anonfun$$lessinit$greater$1.$anonfun$new$2(BuiltinModule.scala:85)
at play.api.inject.BuiltinModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(BuiltinModule.scala:35)
at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:241)
at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:32)
at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:29)
at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
Caused by: java.lang.ClassNotFoundException: play.api.http.HtmlOrJsonHttpErrorHandler
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at play.utils.Reflect$.loadClass$1(Reflect.scala:105)
    at play.utils.Reflect$.configuredClass(Reflect.scala:124)
    at play.utils.Reflect$.bindingsFromConfiguration(Reflect.scala:50)
    at play.api.http.HttpErrorHandler$.bindingsFromConfiguration(HttpErrorHandler.scala:54)
    at play.api.inject.BuiltinModule$$anonfun$$lessinit$greater$1.$anonfun$new$2(BuiltinModule.scala:85)
    at play.api.inject.BuiltinModule$$anonfun$$lessinit$greater$1.$anonfun$new$1(BuiltinModule.scala:35)
    at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:241)

Here is a screenshot of what I get when I go to localhost: enter image description here

Any idea why this might be happening and how to fix it?

3
  • HtmlOrJsonHttpErrorHandler is available starting Play 2.7. Which version of Play are you using? Commented Jul 5, 2020 at 17:29
  • Where can I easily see this? I tfound this in the build.sbt file version = 2.6.x. Commented Jul 5, 2020 at 18:20
  • I've also found this link: playframework.com/documentation/2.4.x/ScalaErrorHandling which is an earlier version and there they use a default error handler as well. Commented Jul 5, 2020 at 18:32

1 Answer 1

3

Comparing changes between Play 2.6.25 and 2.7.0 we deduce that HtmlOrJsonHttpErrorHandler was introduced by Add an HttpErrorHandler that selects the client's preferred media type #8540. The version of Play used in your project should be specified under project/plugins.sbt as something like

addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.0")

If you are using 2.6.0 then follow the migration guide to 2.7.

Sign up to request clarification or add additional context in comments.

3 Comments

Are u sure the problem lays with HtmlOrJsonHttpErrorHandler and not with play.http.errorHandler? To my understanding, this line should work in Play 2.6 play.http.errorHandler = DefaultHttpErrorHandler, however, it returns the same error.
I have addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.6.19") by the way, I just verified. If I can just find a way to introduce some default error handing using this version I think that would be better than migrating to 2.7.
@Arno You have to provide fully qualified name to error handler play.http.errorHandler = play.api.http.DefaultHttpErrorHandler.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.