Skip to content
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

Feature/332 fix middleware [2.0] #338

Merged
merged 4 commits into from
Sep 19, 2023
Merged

Conversation

jamshale
Copy link
Contributor

@jamshale jamshale commented Sep 18, 2023

When the logging middleware function called call_next and it experienced an exception then the response object is not available and would throw a response not available in locals exception that would hide the real exception. It is un-catchable in the middleware.

This checks if response object exists in the locals in the finally block, and if it does then logs the message, and if it doesn't then it assumes it's an exception and looks in traceback, logs the stack trace and returns a 500 response with a more informative message.

The json logger didn't work with the stacktrace from call_next, which would mean the production stack traces would be invisible. Now this explicitly logs the stacktrace from the middleware if LOG_WITH_JSON is True.

The stacktrace for the json format (production) is a bit ugly but I can't think of a way to really make them nice so I just log it as one big string.

@jamshale jamshale changed the base branch from main to 2.0-development September 18, 2023 23:20
oidc-controller/api/main.py Outdated Show resolved Hide resolved
@jamshale jamshale changed the title Feature/332 fix middleware Feature/332 fix middleware [2.0] [Do not merge] Sep 18, 2023
@jamshale jamshale changed the title Feature/332 fix middleware [2.0] [Do not merge] Feature/332 fix middleware [2.0] Sep 19, 2023
@jamshale jamshale marked this pull request as ready for review September 19, 2023 17:56
@jamshale jamshale force-pushed the feature/332-fix-middleware branch 2 times, most recently from 8176c56 to e9a0651 Compare September 19, 2023 18:09
Signed-off-by: jamshale <jamiehalebc@gmail.com>
Signed-off-by: jamshale <jamiehalebc@gmail.com>
Signed-off-by: jamshale <jamiehalebc@gmail.com>
Signed-off-by: jamshale <jamiehalebc@gmail.com>
Copy link
Member

@esune esune left a comment

Choose a reason for hiding this comment

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

👍🏻

@esune esune merged commit 7131a51 into 2.0-development Sep 19, 2023
3 checks passed
@esune esune deleted the feature/332-fix-middleware branch September 19, 2023 23:35
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.

2 participants