[英]Returning custom HTTP error reasons in Google Cloud Endpoints
Google自己的REST API會在出現錯誤時返回詳細響應,例如:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidBookshelfId",
"message": "Invalid bookshelf ID."
}
],
"code": 400,
"message": "Invalid bookshelf ID."
}
}
在Google Cloud Endpoints for Python中,可以例如raise endpoints.BadRequestException('Error message')
,但除了錯誤消息之外,我還想返回“代碼”或“原因”,如上例所示。 有沒有辦法實現這個目標?
代碼對應於與BadRequestException
相關聯的狀態代碼。 還記錄了其他異常,例如endpoints.UnauthorizedException
對應於狀態代碼401
。 至於reason
和domain
,這些是由Google的API基礎設施設置的。
您有什么想法無法在message
設置?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.