From 83fcfecdb1b0b6644c0e0191436841a6af201252 Mon Sep 17 00:00:00 2001 From: Anthonios Partheniou Date: Sat, 12 Dec 2020 22:20:38 +0000 Subject: [PATCH] Check for HTTP 404 in case API is not available --- describe.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/describe.py b/describe.py index 2537e7c06ee..c1bcd692155 100755 --- a/describe.py +++ b/describe.py @@ -389,6 +389,16 @@ 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 @@ -396,12 +406,6 @@ def document_api(name, version, uri): 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)