Skip to content

Commit ebbd851

Browse files
authored
raise error for any not OK response code (#12)
1 parent 29258da commit ebbd851

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

glances_api/__init__.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,22 @@ async def get_data(self, endpoint: str) -> None:
6161
raise exceptions.GlancesApiAuthorizationError(
6262
"Please check your credentials"
6363
)
64-
if response.status_code == httpx.codes.BAD_REQUEST:
64+
65+
if response.status_code != httpx.codes.OK:
6566
raise exceptions.GlancesApiNoDataAvailable(
6667
f"endpoint: '{endpoint}' is not valid"
6768
)
68-
if response.status_code == httpx.codes.OK:
69-
try:
70-
_LOGGER.debug(response.json())
71-
if endpoint == "all":
72-
self.data = response.json()
73-
elif endpoint == "pluginslist":
74-
self.plugins = response.json()
75-
except TypeError:
76-
_LOGGER.error("Can not load data from Glances")
77-
raise exceptions.GlancesApiConnectionError(
78-
"Unable to get the data from Glances"
79-
)
69+
try:
70+
_LOGGER.debug(response.json())
71+
if endpoint == "all":
72+
self.data = response.json()
73+
elif endpoint == "pluginslist":
74+
self.plugins = response.json()
75+
except TypeError:
76+
_LOGGER.error("Can not load data from Glances")
77+
raise exceptions.GlancesApiConnectionError(
78+
"Unable to get the data from Glances"
79+
)
8080

8181
async def get_metrics(self, element: str) -> None:
8282
"""Get all the metrics for a monitored element."""

0 commit comments

Comments
 (0)