All Downloads are FREE. Search and download functionalities are using the official Maven repository.

scala-play-server.app.errorHandler.scala.mustache Maven / Gradle / Ivy

There is a newer version: 7.8.0
Show newest version
package {{basePackage}}

import play.api.http.DefaultHttpErrorHandler
import play.api.libs.json.JsResultException
import play.api.mvc.Results._
import play.api.mvc.{RequestHeader, Result}

import scala.concurrent.Future

class ErrorHandler extends DefaultHttpErrorHandler {
  override def onServerError(request: RequestHeader, e: Throwable): Future[Result] = e match {
    {{#generateCustomExceptions}}
    case _: OpenApiExceptions.MissingRequiredParameterException =>
    {{/generateCustomExceptions}}
    {{^generateCustomExceptions}}
    case _: IllegalArgumentException =>
    {{/generateCustomExceptions}}
      Future.successful(BadRequest(e.getMessage))
    case _: JsResultException =>
      Future.successful(BadRequest(e.getMessage))
    case _ =>
      // Handles dev mode properly, or otherwise returns internal server error in production mode
      super.onServerError(request, e)
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy