Created
November 28, 2019 09:06
-
-
Save ugdark/010cdf18a9bcdaaf0c33285ab8aae621 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.actor.ActorSystem | |
import akka.stream.ActorMaterializer | |
import javax.inject._ | |
import play.api._ | |
import play.api.http.DefaultHttpErrorHandler | |
import play.api.mvc.Results._ | |
import play.api.mvc._ | |
import play.api.routing.Router | |
import play.core.server.akkahttp.AkkaHeadersWrapper | |
import scala.concurrent._ | |
import scala.util.Success | |
class ErrorHandler @Inject()( | |
env: Environment, | |
config: Configuration, | |
sourceMapper: OptionalSourceMapper, | |
router: Provider[Router] | |
) extends DefaultHttpErrorHandler(env, config, sourceMapper, router) | |
with play.api.Logging { | |
implicit val system = ActorSystem() | |
implicit val materializer = ActorMaterializer() | |
override protected def onDevServerError(request: RequestHeader, exception: UsefulException): Future[Result] = { | |
val postData = request.headers.asInstanceOf[AkkaHeadersWrapper].request.entity.dataBytes.runFold(akka.util.ByteString.empty)(_ ++ _).map(_.utf8String)(system.dispatcher) | |
postData.onComplete { | |
case Success(post) => logger.error(s"POST DATA:" + post) | |
}(system.dispatcher) | |
Future.successful { | |
Forbidden("You're not allowed to access this resource.") | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment