Skip to content

Commit

Permalink
Check for HTTP 404 in case API is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
parthea committed Dec 12, 2020
1 parent e954a86 commit 83fcfec
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions describe.py
Expand Up @@ -389,19 +389,23 @@ def document_api(name, version, uri):
"""
try:
service = build(name, version)

http = build_http()
response, content = http.request(
uri or uritemplate.expand(
FLAGS.discovery_uri_template, {"api": name, "apiVersion": version}
)
)
if 'status' in response:
if response['status'] == '404':
raise UnknownApiNameOrVersion
except UnknownApiNameOrVersion as e:
print("Warning: {} {} found but could not be built.".format(name, version))
return
except HttpError as e:
print("Warning: {} {} returned {}.".format(name, version, e))
return

http = build_http()
response, content = http.request(
uri or uritemplate.expand(
FLAGS.discovery_uri_template, {"api": name, "apiVersion": version}
)
)
discovery = json.loads(content)

version = safe_version(version)
Expand Down

0 comments on commit 83fcfec

Please sign in to comment.