diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d7f58d..d40ff38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - ✨ — No need cron tasks for agents watching (#76) - ✨ — Reload configuration asynchronously (#79) - 🐛 — Automatically reconnect to LDAP if unreachable (#81) +- 🐛 — Better httpx.RequestError handling (#83) ## 0.7.4 diff --git a/argos/agent.py b/argos/agent.py index 70689e5..dec1e50 100644 --- a/argos/agent.py +++ b/argos/agent.py @@ -84,6 +84,7 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes await asyncio.sleep(self.wait_time) async def _do_request(self, group: str, details: dict): + logger.debug("_do_request for group %s", group) headers = {} if details["request_data"] is not None: request_data = json.loads(details["request_data"]) @@ -120,6 +121,7 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes ) except httpx.ReadError: sleep(1) + logger.warning("httpx.ReadError for group %s, re-emit request", group) if details["request_data"] is None or request_data["data"] is None: response = await http_client.request( # type: ignore[union-attr] method=details["method"], url=details["url"], timeout=60 @@ -138,6 +140,9 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes data=request_data["data"], timeout=60, ) + except httpx.RequestError as err: + logger.warning("httpx.RequestError for group %s", group) + response = err self._res_cache[group] = response @@ -147,15 +152,21 @@ class ArgosAgent: # pylint: disable-msg=too-many-instance-attributes check_class = get_registered_check(task.check) check = check_class(task) - result = await check.run(self._res_cache[task.task_group]) - status = result.status - context = result.context + response = self._res_cache[task.task_group] + if isinstance(response, httpx.Response): + result = await check.run(response) + status = result.status + context = result.context + else: + status = "failure" + context = SerializableException.from_exception(response) except Exception as err: # pylint: disable=broad-except status = "error" context = SerializableException.from_exception(err) msg = f"An exception occured when running {_task}. {err.__class__.__name__} : {err}" logger.error(msg) + return AgentResult(task_id=task.id, status=status, context=context) async def _get_and_complete_tasks(self):