Skip to content

Instantly share code, notes, and snippets.

@urcadox
Created March 18, 2014 13:57
Show Gist options
  • Save urcadox/9620563 to your computer and use it in GitHub Desktop.
Save urcadox/9620563 to your computer and use it in GitHub Desktop.
Excerpt of a Global.scala file from a Play project - on error handler
object Global extends WithFilters(new GzipFilter()) with DBeable {
/* [...] */
override def onError(request: RequestHeader, ex: Throwable) = {
import _root_.util.Mailer
val exId = ex match {
case e: PlayException => Some(e.id)
case _ => None
}
val exTitle = ex match {
case e: PlayException => Some(e.title)
case _ => None
}
val writer = new java.io.StringWriter()
val printWriter = new java.io.PrintWriter(writer)
ex.printStackTrace(printWriter)
val stacktrace = writer.toString()
Mailer.send(
"[Exception report] " + exId.getOrElse("(no ID)") + " - " + exTitle.getOrElse("(no title)"),
List("alexandre+myapp@berthaud.me"),
"contact@myapp.com",
"""
Exception ID: %s
Exception title: %s
Date: %s
Caused by: %s
Stacktrace:
%s
""".format(
exId.getOrElse("(no ID)"),
exTitle.getOrElse("(no title)") ,
(new org.joda.time.DateTime).toString(),
ex.getCause,
stacktrace
)
)
Future.successful(InternalServerError(
views.html.errors.applicationError()
))
}
/* [...] */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment