- 
                Notifications
    
You must be signed in to change notification settings  - Fork 32
 
🎨 Enhanced error handling and troubleshooting logs helpers #6531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
58df82a    to
    cf4b04b      
    Compare
  
    There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool! Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice 👍
          
 | 
    



What do these changes do?
This pull request (PR) introduces a maintainable mechanism for handling domain-specific errors that propagate through system interfaces (such as REST or RPC APIs) and converting them into API errors.
In this approach, domain errors are represented by custom exceptions, which are raised throughout the codebase. These exceptions need to be caught at service interfaces, where they are converted into appropriate API errors. The proposed mechanism ensures consistency and maintainability in handling this workflow.
Key changes in this PR:
error_codesfromservicelibtomodels_libraryto better align with the domain architecture and centralize error handling.models_library.error_classes.OsparcErrorMixin:error_codeanderror_contextattributes.OsparcErrorMixinto leverage this functionality.Workflow:
Raise Domain-Specific Errors: When an error occurs in the code, raise a domain-specific exception (inheriting from
OsparcErrorMixin). Capture any relevant information in theerror_contextfor later use.Handle Errors at Service Interfaces: At the boundaries where domain exceptions meet external interfaces (REST or RPC), catch the exceptions and convert them into the appropriate API error type (e.g.,
HTTPError).Logging and Troubleshooting:
create_troubleshooting_log_kwargsto gather all error context information and log the error with_logger.exception.OsparcErrorMixinensures that all context data related to the error is logged automatically, and additional context can be added at the logging point if necessary.log_uid) from the error context that can be parsed and presented as columns in graylog.This PR provides a clear, structured approach to handle and log errors in a way that enhances maintainability and transparency in API-level error handling across the system.
Usage example
Assume you raise a domain exception in your code. How is it defined, raised and finally handled to produce a log for troubleshooting (optional) and converted to an rest http error.
504with "This stuff is not available right now, sorry!" and in the bacckend it will log something likeRelated issue/s
How to test
Dev-ops checklist
None