How does Google Cloud Endpoints map API responses to HTTP Codes?

梦想与她 提交于 2019-12-25 16:42:33

问题


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.

来源:https://stackoverflow.com/questions/26318221/how-does-google-cloud-endpoints-map-api-responses-to-http-codes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!