title: endpoints.ServiceException subclass returning 400 status code instead of 409
body: <p>In the Cloud Endpoints <a href="https://developers.google.com/appengine/docs/python/endpoints/exceptions" rel="nofollow noreferrer">documentation</a> for exception handling, it is recommended to subclass the <code>endpoints.ServiceException</code> class to provide a custom <code>http_status</code> for 409 Conflict errors.  This <a href="https://stackoverflow.com/a/16450227/2232750">answer</a> to another question indicates that some of the supported status codes get mapped by Google's infrastructure to other status codes, but 409 isn't one of the mapped status codes.</p>
  
  <p>Using the <code>ConflictException</code> class from the documentation:</p>
  
  <pre><code>import endpoints
  import httplib
  
  class ConflictException(endpoints.ServiceException):
      """Conflict exception that is mapped to a 409 response."""
      http_status = httplib.CONFLICT
  </code></pre>
  
  <p>When I raise the <code>ConflictException</code>:</p>
  
  <pre><code>@endpoints.method(request_message=apimodels.ClientMessage,
                    response_message=apimodels.ClientMessage,
                    name='insert',
                    path='/clients',
                    http_method='POST'
  )
  def insert(self, request):
      client = models.Client.get_by_id(request.client_code)
      if client:
          raise ConflictException('Entity with the id "%s" exists.' % request.client_code)
  
      ...
  </code></pre>
  
  <p>I'm getting a 400 Bad Request as the response:</p>
  
  <pre><code>400 Bad Request
  
  Content-Length:  220
  Content-Type:  application/json
  Date:  Thu, 27 Feb 2014 16:11:36 GMT
  Server:  Development/2.0
  
  {
   "error": {
    "code": 400,
    "errors": [
     {
      "domain": "global",
      "message": "Entity with the id \"FOO\" exists.",
      "reason": "badRequest"
     }
    ],
    "message": "Entity with the id \"FOO\" exists."
   }
  }
  </code></pre>
  
  <p>I'm getting the same 400 response code on both the local dev_appserver and deployed to App Engine (on 1.9.0).  Stepping into the App Engine ProtoRPC code, the following <a href="https://code.google.com/p/googleappengine/source/browse/trunk/python/lib/protorpc-1.0/protorpc/wsgi/service.py?spec=svn390&amp;r=390#184" rel="nofollow noreferrer">line</a> appears to be mapping all <code>remote.ApplicationError</code> types to a 400 status code.</p>
  
  <p>If I update the <code>endpoints.apiserving._ERROR_NAME_MAP</code> dict to add my custom <code>ConflictException</code> class, I'm able to return a 409 successfully:</p>
  
  <pre><code>import endpoints
  import httplib
  from endpoints.apiserving import _ERROR_NAME_MAP
  
  class ConflictException(endpoints.ServiceException):
      """Conflict exception that is mapped to a 409 response."""
      http_status = httplib.CONFLICT
  
  
  _ERROR_NAME_MAP[httplib.responses[ConflictException.http_status]] = ConflictException
  </code></pre>
  
  <p><strong>Is this the correct way to implement <code>endpoints.ServiceException</code> subclasses?</strong></p>