Wrapped HTTP responses in async context managers to prevent connection leaks.
CD / Build (push) Successful in 8s
CI / Formatting (push) Successful in 6s
CI / Linting (push) Successful in 5s
CI / Type Checking (push) Successful in 8s
CI / Spelling (push) Successful in 5s

This commit is contained in:
2026-03-12 15:43:03 -04:00
parent afa1584ec5
commit 1429e2de11
+14 -16
View File
@@ -69,15 +69,9 @@ class OwncastClient:
# Make a request to the endpoint
try:
response = await self.session.request(
async with self.session.request(
"GET", status_url, allow_redirects=False
)
except Exception as e:
self.log.warning(
f"[{domain}] Error making GET request to {OWNCAST_STATUS_PATH}: {e}"
)
return None
) as response:
# Check the response code is success
if response.status != 200:
self.log.warning(
@@ -97,6 +91,11 @@ class OwncastClient:
f"interpreted as JSON: {e}"
)
return None
except Exception as e:
self.log.warning(
f"[{domain}] Error making GET request to {OWNCAST_STATUS_PATH}: {e}"
)
return None
# Validate the response contains all basic info needed
required_fields = [
@@ -130,15 +129,9 @@ class OwncastClient:
# Make a request to the endpoint
try:
response = await self.session.request(
async with self.session.request(
"GET", config_url, allow_redirects=False
)
except Exception as e:
self.log.warning(
f"[{domain}] Error making GET request to {OWNCAST_CONFIG_PATH}: {e}"
)
return None
) as response:
# Check the response code is success
if response.status != 200:
self.log.warning(
@@ -158,6 +151,11 @@ class OwncastClient:
f"interpreted as JSON: {e}"
)
return None
except Exception as e:
self.log.warning(
f"[{domain}] Error making GET request to {OWNCAST_CONFIG_PATH}: {e}"
)
return None
# Create StreamConfig from response (fields are truncated to max lengths)
return StreamConfig.from_api_response(config)