Repository navigation
Read the error body asynchronously and expose Gotenberg-Trace - #89
Merged
Jaben merged 1 commit intoNov 8, 2026
Merged
Conversation
GotenbergApiException.Create read the error body with .Result, blocking a thread inside every async conversion path on a response fetched with ResponseHeadersRead, so the body may still be in transit. It also kept the HttpResponseMessage and never disposed it unless ToVerboseJson was called, and dropped the Gotenberg-Trace header, which is what correlates a failure with Gotenberg's log. Add CreateAsync, which reads the body with the caller's cancellation token and disposes the response, and use it for every error response. Create is kept and marked obsolete. The exception now copies what it reports (status, headers, request URI and method) instead of holding the response, exposes the header as Trace, and ToVerboseJson dumps that copy.
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 37 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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.
Reading an error response had three problems, all in
GotenbergApiException:Createread the body with.Result. That blocks a thread inside every async conversion path, on a response fetched withResponseHeadersRead, so the body may still be in transit. It also ignored the caller's cancellation token.HttpResponseMessageand never disposed it unlessToVerboseJsonwas called.Gotenberg-Traceheader was dropped. The request side supports setting it (ConfigBuilder.SetTrace), but correlating a failure with Gotenberg's log needs the value Gotenberg sent back. Gotenberg 9 puts the trace header on every response, 404 and 405 included.Changes:
GotenbergApiException.CreateAsync(request, response, cancelToken). It reads the body with the caller's token and disposes the response, also when reading fails or is cancelled.SendRequestAsyncuses it for every error response.Createstays for source compatibility and is marked[Obsolete]; it now disposes the response as well.GotenbergApiException.Trace(string?).Behaviour change in
ToVerboseJson:GotenbergResponseReceivedused to be a reflection dump ofHttpResponseMessage: headers as[{"Key": ..., "Value": [...]}]arrays, plusTrailingHeadersand a nestedRequestMessage. It is now a fixed set:StatusCode,ReasonPhrase,Version,IsSuccessStatusCode,RequestUri,RequestMethod,HeadersandContentHeaders(name to comma-joined value). I captured the old output ondevelopto compare.Traceis left out of the dump because it is on the exception. This overlaps with #82, which also rewritesToVerboseJsonand chooses a similar fixed shape, so whichever merges second will need a small rebase.Tests (
GotenbergApiExceptionTests):CreateAsynccaptures status, message and trace, and disposes the response.Trace.OperationCanceledExceptionand still disposes the response.ToVerboseJsonworks from the copy after the response is disposed, and can be called twice.Traceand a disposed response.The full suite passes against
gotenberg/gotenberg:8: 251 tests, all target frameworks build.I've left
CHANGES.MDalone to avoid conflicts between the small PRs. A suggested line: Added:GotenbergApiException.TraceandCreateAsync. Changed: error bodies are read asynchronously with the caller's cancellation token, the response is disposed,Createis obsolete, and theGotenbergResponseReceivedsection ofToVerboseJsonhas a fixed shape.