Skip to content

Improve error handling and logging in event writers#53

Merged
oto-macenauer-absa merged 2 commits intomasterfrom
feature/improve-logging
Sep 8, 2025
Merged

Improve error handling and logging in event writers#53
oto-macenauer-absa merged 2 commits intomasterfrom
feature/improve-logging

Conversation

@oto-macenauer-absa
Copy link
Collaborator

@oto-macenauer-absa oto-macenauer-absa commented Sep 5, 2025

This pull request introduces significant improvements to error handling, writer result aggregation, and test coverage for the event gate Lambda. The main changes include standardizing error responses, updating all writer modules to return detailed error information, aggregating writer results in the main handler, and adding comprehensive unit tests to validate both successful and failure scenarios.

Error Handling and Response Standardization

  • Introduced a centralized _error_response helper in event_gate_lambda.py to standardize all error responses, ensuring consistent structure and error details for authentication, authorization, validation, and internal errors. [1] [2] [3] [4]
  • Updated all endpoints to use this helper for error cases, replacing ad-hoc or incomplete error responses. [1] [2] [3]

Writer Modules: Result Reporting

  • Refactored writer_kafka, writer_eventbridge, and writer_postgres so their write functions now return a tuple (success: bool, error_message: str|None), allowing the main handler to report which writer failed and why. [1] [2] [3] [4] [5]
  • Enhanced error logging and error message propagation in each writer for better observability and debugging. [1] [2] [3]

Main Handler Logic

  • Updated the POST topic message flow to invoke all writers independently, aggregate their results, and return a 500 error with detailed error information if any writer fails, or a 202 success if all succeed.
  • Improved topic schema and authorization checks to use consistent error responses. [1] [2]

Configuration and File Path Robustness

  • Refactored configuration file loading to use absolute paths based on the project root, improving robustness when running from different working directories. [1] [2]

Testing and Coverage

  • Added a comprehensive test suite in tests/test_event_gate_lambda.py that mocks external dependencies, covers all major GET and POST flows, and verifies correct error and success response structures across a variety of scenarios, including writer failures and internal errors.

These changes collectively make the Lambda handler more robust, easier to debug, and better tested, with clear and actionable error reporting throughout.

Related

Closes #52

Release notes:

  • Improve error handling
  • Improve logging in event writers

…ig file paths and add error response utility
Copy link
Contributor

@miroslavpojer miroslavpojer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • fast read
  • review on call

@oto-macenauer-absa oto-macenauer-absa merged commit 341b9ea into master Sep 8, 2025
2 checks passed
@oto-macenauer-absa oto-macenauer-absa deleted the feature/improve-logging branch September 8, 2025 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add better failure responses

3 participants