code: def _get_error_reason(response):
          
          try:
              body = response.json()
              if body and 'reason' in body:
                  return body['reason']
          except ValueError:
              pass
          return response.content
docs: Extract error reason from the response. It might be either
          the 'reason' or the entire response