Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Returning custom HTTP error reasons in Google Cloud Endpoints

Google's own REST APIs return detailed response in case of an error, e.g:

{
 "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 e.g. raise endpoints.BadRequestException('Error message'), but in addition to the error message I would like to return "code" or "reason" as in example above. Is there any way to achieve this?

like image 785
Docent Avatar asked Mar 29 '13 15:03

Docent


1 Answers

The code corresponds to the status code associated with BadRequestException. The other exceptions are documented as well, for example endpoints.UnauthorizedException corresponds to the status code 401. As for the reason and the domain, those are set by Google's API Infrastructure.

What did you have in mind that isn't possible to set in message?

like image 123
bossylobster Avatar answered Oct 07 '22 07:10

bossylobster