Implemented standardized RFC 7807 error handling and request correlation ID tracking#699
Conversation
|
hey team i noticed this issue has been open for some time if the team has moved in a different direction and no longer requires this feature, please feel free to close it but tbh i used this to get into the project's middleware architecture and enjoyed the process regardless |
19123a6 to
e6d3bd6
Compare
|
I have successfully rebased the branch with the latest develop changes,while resolving the conflicts in error_handling.py, I noticed a potential NameError where the reference variable was being accessed without a fallback. I hav implemented a safety shield using a try...except NameError block (defaulting to UNKNOWN) to ensure the exception handler remains robust even if the upstream state variables are missing, verified the fix locally via docker the api now correctly returns rfc 7807 compliant JSON and logs the full error context at the INFO level without crashing. Hope this helps |
PR Description
Change(s)
Implemented CorrelationIdMiddleware to generate/propagate a unique ID for every request.
Added a global http_exception_handler to standardize error responses using the RFC 7807 (Problem Details) format.
Registered explicit exception handlers for 404 status codes and StarletteHTTPException to ensure error capturing works within the versioned FastAPI sub-apps.
Updated logging logic to ensure API errors are visible at the INFO log level.
Change Type: Feature
Change Category: Backend
Changelog Entry: Implemented standardized RFC 7807 error handling and request correlation ID tracking.
How to Test
Start the application: docker-compose up --build app.
Trigger a 404 error: curl -i http://localhost:8000/v1/non-existent-path.
Verify Headers: Ensure X-Correlation-ID is present in the response.
Verify Body: Confirm the JSON body contains the correlation ID and follows the Problem Details structure.
Verify Logs: Run docker-compose logs app and look for the INFO: API Error: {...} entry.
Checklist
[x] Tests have been updated to reflect the changes (Verified via manual integration testing in Docker).
[x] Documentation has been updated to reflect the changes (In-code documentation added).
[x] A self-review has been conducted.
[x] All CI checks pass before pinging a reviewer.
[x] The PR title matches the changelog entry's one-line description.
Related Issues
Fixes #85