Skip to content

Commit 83fcfec

Browse files
committed
Check for HTTP 404 in case API is not available
1 parent e954a86 commit 83fcfec

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

describe.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -389,19 +389,23 @@ def document_api(name, version, uri):
389389
"""
390390
try:
391391
service = build(name, version)
392+
393+
http = build_http()
394+
response, content = http.request(
395+
uri or uritemplate.expand(
396+
FLAGS.discovery_uri_template, {"api": name, "apiVersion": version}
397+
)
398+
)
399+
if 'status' in response:
400+
if response['status'] == '404':
401+
raise UnknownApiNameOrVersion
392402
except UnknownApiNameOrVersion as e:
393403
print("Warning: {} {} found but could not be built.".format(name, version))
394404
return
395405
except HttpError as e:
396406
print("Warning: {} {} returned {}.".format(name, version, e))
397407
return
398408

399-
http = build_http()
400-
response, content = http.request(
401-
uri or uritemplate.expand(
402-
FLAGS.discovery_uri_template, {"api": name, "apiVersion": version}
403-
)
404-
)
405409
discovery = json.loads(content)
406410

407411
version = safe_version(version)

0 commit comments

Comments
 (0)