簡體   English   中英

在Google Cloud Endpoints中返回自定義HTTP錯誤原因

[英]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 至於reasondomain ,這些是由Google的API基礎設施設置的。

您有什么想法無法在message設置?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM