title: FastAPI not raising HTTPException
body: <p>I'm trying to raise an exception in FastAPI when an object with a specific key already exists (e.g. RethinkDb return &quot;Duplicated key&quot; error). Probably something wrong with my method logic, but can't get what exactly.</p>
  <pre><code>@router.post(&quot;/brands&quot;, response_model=Brand, status_code=status.HTTP_201_CREATED)
  def add_brand(brand: Brand):
      with r.connect('localhost', 28015, 'expressparts').repl() as conn:
          try:
              result = r.table(&quot;brands&quot;).insert({
                  &quot;id&quot;: brand.id,
                  &quot;name&quot;: brand.name}).run(conn)
              if result['errors'] &gt; 0:
                  error = result['first_error'].split(&quot;:&quot;)[0]
                  raise HTTPException(
                      status_code=400, detail=f&quot;Error raised: {error}&quot;)
              else:
                  return brand
          except Exception as err:
              print(err)
  </code></pre>