Skip to content

Commit 70fd85a

Browse files
author
Kanaduchi
committed
#13 Improve check for content-type
1 parent a3a9be6 commit 70fd85a

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

src/pymelcloud/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""MEL API access."""
22
from datetime import datetime, timedelta
33
from typing import Any, Dict, List, Optional
4-
from aiohttp import ClientResponseError
4+
from aiohttp import ClientResponseError, ContentTypeError
55

66
from aiohttp import ClientSession
77

@@ -182,7 +182,10 @@ async def fetch_device_units(self, device) -> Optional[Dict[Any, Any]]:
182182
json={"deviceId": device.device_id}
183183
) as resp:
184184
resp.raise_for_status()
185-
data = await resp.json()
185+
try:
186+
data = await resp.json()
187+
except ContentTypeError:
188+
return None
186189
if isinstance(data, dict):
187190
return data
188191
return None
@@ -225,7 +228,10 @@ async def fetch_energy_report(self, device) -> Optional[Dict[Any, Any]]:
225228
}
226229
) as resp:
227230
resp.raise_for_status()
228-
data = await resp.json()
231+
try:
232+
data = await resp.json()
233+
except ContentTypeError:
234+
return None
229235
if isinstance(data, dict):
230236
return data
231237
return None

0 commit comments

Comments
 (0)