Google Cloud Endpoints如何将API响应映射到HTTP代码?

时间:2014-10-11 19:05:34

标签: google-app-engine exception-handling google-cloud-endpoints httpwebresponse

我正在使用Google Cloud Endpoint for Python。

我有一个端点,在某些情况下会抛出异常。根据{{​​3}},抛出从endpoints继承的自定义异常.ServiceException应该导致所有HTTP状态代码从400-413保留在HTTP响应中。但是,我的测试显示错误代码404被保留,而408和409被映射到400.我是否误解了文档?

这是我自定义的Exception类和我设置的3个不同的HTTP状态。我只会一次使用一个,但为了简洁,将所有3个放在下面的代码中:

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.

注意:我正在使用带有App Engine SDK 1.9.13的API Explorer在本地测试Endpoint。

0 个答案:

没有答案