acjay
acjay

Reputation: 36521

Show custom error page in production only in Play

We want to override the standard Play error page with our own error page. Unfortunately, overriding onError in our Global file replaces the error page in all modes, even though we'd like to keep the informative debug error page in development. How can I detect development mode to retain the built-in behavior in that mode?

Upvotes: 3

Views: 267

Answers (2)

Daniel Olszewski
Daniel Olszewski

Reputation: 14401

Play object has helper methods that allow checking a current application mode.

import play.api._

object Global extends GlobalSettings {
  override def onError(request: RequestHeader, e: Throwable): Future[SimpleResult] = {
    if (!Play.isDev)
      Future.successful(InternalServerError(views.html.customErrorPage()))
    else
      super.onError(request, e)
  }
}

Upvotes: 3

Ryan
Ryan

Reputation: 7247

Try this:

if (play.api.Play.current.mode == play.api.Mode.Prod)
  ...

Upvotes: 2

Related Questions