How does Google Cloud Endpoints map API responses

2019-09-05 07:46发布

I am using Google Cloud Endpoint for Python.

I have an endpoint that throws an Exception in certain cases. According to the documentation, throwing a custom Exception that inherits from endpoints.ServiceException should cause all HTTP status codes from 400-413 to be preserved in the HTTP response. However, my tests show that error code 404 is preserved while 408 and 409 are mapped to a 400. Am I misunderstanding the documentation?

Here is my custom Exception class and the 3 different HTTP statues I was setting. I would only use one at a time but put all 3 in the following code for brevity:

class UserNotFoundException(endpoints.ServiceException):
  http_status = httplib.NOT_FOUND # maps to 404. expected
  http_status = httplib.CONFLICT # is a 409 but maps to 400. not expected.
  http_status = httplib.REQUEST_TIMEOUT # is a 408 but maps to 400. not expected.

Note: I am testing the Endpoint locally using the API Explorer w/ App Engine SDK 1.9.13.

0条回答
登录 后发表回答