From ef8fc3cf8a8308ce9c5be6d26159a3e98808844a Mon Sep 17 00:00:00 2001 From: mutantsan Date: Wed, 11 Dec 2024 13:34:11 +0200 Subject: [PATCH] fix: catch ClientError for Cloudwatch repository --- ckanext/event_audit/repositories/cloudwatch.py | 7 +++++++ pyproject.toml | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ckanext/event_audit/repositories/cloudwatch.py b/ckanext/event_audit/repositories/cloudwatch.py index f01b53b..4d160cd 100644 --- a/ckanext/event_audit/repositories/cloudwatch.py +++ b/ckanext/event_audit/repositories/cloudwatch.py @@ -1,5 +1,6 @@ from __future__ import annotations +import logging import json from contextlib import suppress from datetime import datetime, timezone @@ -19,6 +20,9 @@ from ckanext.event_audit.repositories.base import AbstractRepository, RemoveAll +log = logging.getLogger(__name__) + + class CloudWatchEvent(TypedDict): timestamp: int message: str @@ -103,7 +107,9 @@ def write_event(self, event: types.Event) -> types.Result: self.client.exceptions.ResourceNotFoundException, self.client.exceptions.ServiceUnavailableException, self.client.exceptions.UnrecognizedClientException, + self.client.exceptions.ClientError, ) as e: + log.error(f"Failed to write event to CloudWatch: {e}") return types.Result(status=False, message=str(e)) def _create_log_stream_if_not_exists(self, log_stream: str) -> str: @@ -227,6 +233,7 @@ def remove_all_events(self) -> types.Result: try: self.client.delete_log_group(logGroupName=self.log_group) except self.client.exceptions.ResourceNotFoundException as err: + log.error(f"Failed to remove all events from CloudWatch: {err}") return types.Result(status=False, message=str(err)) return types.Result(status=True, message="All events removed successfully") diff --git a/pyproject.toml b/pyproject.toml index bc4e2ed..a26e211 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "ckanext-event-audit" -version = "1.1.0" +version = "1.1.1" description = "" classifiers = [ "Development Status :: 4 - Beta",