[英]Custom HTTP status codes from AppEngine Java endpoints
Everyone loves REST-fulness, so I'd like to return the most appropriate HTTP status codes from my AppEngine endpoints. 每个人都喜欢REST功能,因此我想从AppEngine端点返回最合适的HTTP状态代码。 Like 201 CREATED, for example, when a resource has been created. 例如,当创建资源时,就像201 CREATED。
But I can't find how to do this with GAE Java endpoints. 但是我找不到如何使用GAE Java端点执行此操作。
Some 4xx codes are supported by throwing an exception (NotFoundException causes a 404, for example), but that's not an appropriate solution for 2xx codes. 通过抛出异常来支持某些4xx代码(例如,NotFoundException导致404),但这不是2xx代码的适当解决方案。
Can anyone help please? 有人可以帮忙吗?
Matthew 马修
Cloud Endpoints does support creating your own Custom Exception classes by subclassing com.google.api.server.spi.ServiceException
Cloud Endpoints确实支持通过将com.google.api.server.spi.ServiceException
子类化来创建自己的Custom Exception类。
However, from the documentation at https://developers.google.com/appengine/docs/java/endpoints/exceptions , it is mentioned that HTTP 2xx codes should not be used in custom exception classes. 但是,从https://developers.google.com/appengine/docs/java/endpoints/exceptions上的文档中可以看出,自定义异常类中不应使用HTTP 2xx代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.