Skip to content

Commit c71c216

Browse files
authored
Handle TypeError for missing server version (elastic#1349)
* Handle TypeError for missing server version * Add test
1 parent d04f3b7 commit c71c216

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

elasticapm/transport/http.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def fetch_server_info(self):
188188
logger.warning("HTTP error while fetching server information: %s", str(e))
189189
except json.JSONDecodeError as e:
190190
logger.warning("JSON decoding error while fetching server information: %s", str(e))
191-
except KeyError:
191+
except (KeyError, TypeError):
192192
logger.warning("No version key found in server response: %s", response.data)
193193

194194
@property

tests/transports/test_urllib3.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,3 +421,16 @@ def test_fetch_server_info_no_version(waiting_httpserver, caplog, elasticapm_cli
421421
transport.fetch_server_info()
422422
assert elasticapm_client.server_version is None
423423
assert_any_record_contains(caplog.records, "No version key found in server response")
424+
425+
426+
def test_fetch_server_info_flat_string(waiting_httpserver, caplog, elasticapm_client):
427+
waiting_httpserver.serve_content(
428+
code=200,
429+
content=b'"8.0.0-alpha1"',
430+
)
431+
url = waiting_httpserver.url
432+
transport = Transport(url + "/" + constants.EVENTS_API_PATH, client=elasticapm_client)
433+
with caplog.at_level("WARNING"):
434+
transport.fetch_server_info()
435+
assert elasticapm_client.server_version is None
436+
assert_any_record_contains(caplog.records, "No version key found in server response")

0 commit comments

Comments
 (0)