fix: capture exception details for 500/405 responses with empty body#37
Merged
georgidhristov merged 1 commit intoMay 15, 2026
Merged
Conversation
When an unhandled exception occurs, the response body written to the MemoryStream is empty because ASP.NET Core's exception handler hasn't processed it yet at the point the middleware's finally block runs. This adds ExceptionMessage and ExceptionStackTrace fields to DebugEntry and captures them in the catch block, so the DebugProbe UI can display the actual exception details even when the response body is empty. Also increase the trim limit for stack traces to 4000 chars for meaningful diagnostics. Closes DebugProbe#36
Collaborator
|
Tested locally. The backend exception capture works correctly and fixes the empty response debugging issue. The UI currently still shows an empty response body because ExceptionMessage/ExceptionStackTrace are not rendered yet. I will handle the UI support separately in another issue/PR. Thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #36 — When unhandled exceptions occur, DebugProbe showed the response as having status code 500 but with an empty response body, making debugging difficult.
Root Cause
The middleware's
try/catch/finallypattern intercepts the response stream viaMemoryStream. Whenawait _next(context)throws:finallyblock reads theMemoryStream— but at this point ASP.NET Core's exception handling middleware hasn't written anything to it yetSolution
Added two fields to
DebugEntryand capture exception data in thecatchblock:ExceptionMessage— the exception's.MessageExceptionStackTrace— the exception's.StackTrace(trimmed to 4000 chars for readability)This ensures that even when the response body hasn't been written yet by downstream middleware, the DebugProbe UI can display the actual exception that occurred.
Changes
DebugProbe.AspNetCore/Models/DebugEntry.csExceptionMessageandExceptionStackTracepropertiesDebugProbe.AspNetCore/Middleware/DebugProbeMiddleware.csTesting