You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
defindexSubmit= myActionHandler(parse.form(MyForm, onErrors = indexSubmitErrorHandler)).async { implicit request =>// request.body is available and valid here
}
privatedefindexSubmitErrorHandler(formWithErrors: Form[MyModel]) = {
BadRequest(myFormView(formWithErrors))
}
I really like this concept, since this would decouple the handling of errors completely from the action body of a HTTP endpoint. However, in my case this won't compile, since my template expects an implicit RequestHeader. Looking at BodyParsers.scala, I see the following:
I'd like to suggest marking requestHeader here as implicit to solve this issue, since any templates that expect RequestHeader values won't work.
As a workaround, I've moved the parsing to the body of the action:
defindexSubmit= myActionHandler.async { implicit request =>MyForm.bindFromRequest.fold(
formWithErrors =>Future.successful(BadRequest(myFormView(formWithErrors))),
formData => {
// formData is available here
}
)
}
In addition to this, I think it would be useful to allow asynchronous errorhandlers as well, since it's not always possible (or even desirable) to have completely synchronous code within an error handler:
After looking into this, I realized that solving this will require more than simply marking requestHeader as implicit. What I originally had in mind, was this:
Unless I'm missing something here, this will never work. Overloading this method like so will also not work due to type erasure, since onErrors will still be a Function1 and won't compile:
Hello,
Please regard the following use case:
I really like this concept, since this would decouple the handling of errors completely from the action body of a HTTP endpoint. However, in my case this won't compile, since my template expects an implicit RequestHeader. Looking at
BodyParsers.scala
, I see the following:I'd like to suggest marking
requestHeader
here as implicit to solve this issue, since any templates that expectRequestHeader
values won't work.As a workaround, I've moved the parsing to the body of the action:
In addition to this, I think it would be useful to allow asynchronous errorhandlers as well, since it's not always possible (or even desirable) to have completely synchronous code within an error handler:
The text was updated successfully, but these errors were encountered: