[英]Returning custom HTTP error reasons in Google Cloud Endpoints
Google's own REST APIs return detailed response in case of an error, eg: Google自己的REST API会在出现错误时返回详细响应,例如:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidBookshelfId",
"message": "Invalid bookshelf ID."
}
],
"code": 400,
"message": "Invalid bookshelf ID."
}
}
In Google Cloud Endpoints for Python, it's possible to eg raise endpoints.BadRequestException('Error message')
, but in addition to the error message I would like to return "code" or "reason" as in example above. 在Google Cloud Endpoints for Python中,可以例如
raise endpoints.BadRequestException('Error message')
,但除了错误消息之外,我还想返回“代码”或“原因”,如上例所示。 Is there any way to achieve this? 有没有办法实现这个目标?
The code corresponds to the status code associated with BadRequestException
. 代码对应于与
BadRequestException
相关联的状态代码。 The other exceptions are documented as well, for example endpoints.UnauthorizedException
corresponds to the status code 401
. 还记录了其他异常,例如
endpoints.UnauthorizedException
对应于状态代码401
。 As for the reason
and the domain
, those are set by Google's API Infrastructure. 至于
reason
和domain
,这些是由Google的API基础设施设置的。
What did you have in mind that isn't possible to set in message
? 您有什么想法无法在
message
设置?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.