scala-play-server.app.errorHandler.scala.mustache Maven / Gradle / Ivy
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