title: How to handle exceptions in a playframework 2 Async block (scala)
body: <p>My controller action code looks like this:</p>
  
  <pre><code>  def addIngredient() = Action { implicit request =&gt;
      val boundForm = ingredientForm.bindFromRequest
      boundForm.fold(
        formWithErrors =&gt; BadRequest(views.html.Admin.index(formWithErrors)),
        value =&gt; {
          Async {
            val created = Service.addIngredient(value.name, value.description)
            created map { ingredient =&gt;
              Redirect(routes.Admin.index()).flashing("success" -&gt; "Ingredient '%s' added".format(ingredient.name))
            }
  
            // TODO on exception do the following
            // BadRequest(views.html.Admin.index(boundForm.copy(errors = Seq(FormError("", ex.getMessage())))))
          }
        })
    }
  </code></pre>
  
  <p>My Service.addIngredient(...) returns a Promise[Ingredient] but can also throw a custom ValidationException. When this exception is thrown I would like to return the commented code.</p>
  
  <p>Currently the page renders as 500 and in the logs I have:</p>
  
  <blockquote>
    <p>play - Waiting for a promise, but got an error: Ingredient with name
    'test' already exists. services.ValidationException: Ingredient with name
    'test' already exists.</p>
  </blockquote>
  
  <p>Two questions: </p>
  
  <ul>
  <li>Is it a bad idea to return this exception from my service, is there a better/more scala way to handle this case?</li>
  <li>How do I catch the exception?</li>
  </ul>