google-api-python-client icon indicating copy to clipboard operation
google-api-python-client copied to clipboard

details missing in googleapiclient.errors.HttpError

Open pdknsk opened this issue 9 years ago • 2 comments

Run some code that makes an invalid request.

  File "/home/user/.local/lib/python2.7/site-packages/googleapiclient/http.py", line 840, in execute
    raise HttpError(resp, content, uri=self.uri)
googleapiclient.errors.HttpError: <HttpError 400 when requesting https://appengine.googleapis.com/v1/apps/<project>/services/default?alt=json returned "Invalid request.">

Now when you get the exception and its content the error becomes slightly more verbose.

{
  "error": {
    "code": 400,
    "message": "Invalid request.",
    "errors": [
      {
        "message": "Invalid request.",
        "domain": "global",
        "reason": "badRequest"
      }
    ],
    "status": "INVALID_ARGUMENT"
  }
}

Making the same request manually to the REST API returns a significantly more useful response.

{
  "error": {
    "code": 400,
    "message": "Invalid request.",
    "status": "INVALID_ARGUMENT",
    "details": [
      {
        "@type": "type.googleapis.com/google.rpc.BadRequest",
        "fieldViolations": [
          {
            "field": "service.split.allocations[1]",
            "description": "Allocation must be a value in the range (0, 1]."
          },
          {
            "field": "service.split.allocations",
            "description": "Traffic allocations must sum to 1."
          }
        ]
      }
    ]
  }
}

pdknsk avatar Apr 09 '17 17:04 pdknsk

Seems like it might just be dropping the "details" section on the floor. I'm happy to review a patch to fix this, or we'll get to it when we can.

theacodes avatar Apr 10 '17 16:04 theacodes

@jonparrott Thanks in advance for a review.

sonlac avatar Jul 08 '17 09:07 sonlac