Only try to parse into an ErrorResponse if the content-type is json#14241
Open
OneBlue wants to merge 2 commits intofeature/wsl-for-appsfrom
Open
Only try to parse into an ErrorResponse if the content-type is json#14241OneBlue wants to merge 2 commits intofeature/wsl-for-appsfrom
OneBlue wants to merge 2 commits intofeature/wsl-for-appsfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request improves the reliability of HTTP error handling in the Docker HTTP client by checking the Content-Type header before attempting to parse error responses as JSON. Previously, the code relied on HTTP status codes (400-500 range) to determine whether to parse the response body as JSON, which was less reliable than inspecting the actual Content-Type header.
Changes:
- Modified
DockerHTTPExceptionto store the full HTTP response object instead of just the status code and response body string, enabling content-type header inspection - Added
HasErrorMessage()method that checks if the Content-Type header is "application/json" before attempting JSON parsing - Refactored
InspectContainer()andInspectExec()methods to return typed objects instead of raw JSON strings, using the existingTransactiontemplate method - Updated all call sites to work with the new typed return values
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/windows/wslasession/DockerHTTPClient.h | Added HasErrorMessage() method for content-type checking; changed exception constructor to accept full HTTP response; updated method signatures to return typed objects; changed internal helper methods to return HTTPResponse instead of status codes |
| src/windows/wslasession/DockerHTTPClient.cpp | Simplified InspectContainer() and InspectExec() to use the Transaction template; updated all exception throws to pass full response objects; updated SendRequestAndReadResponse() to return HTTPResponse |
| src/windows/wslasession/WSLASession.cpp | Updated call site to use typed InspectContainer() return value |
| src/windows/wslasession/WSLAContainer.cpp | Updated call sites to use typed return values from InspectContainer() and InspectExec(); converted state object back to JSON for error logging using ToJson() |
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 of the Pull Request
This change updates the HTTP error handling logic to look at the content-type header before attempting to parse into JSON.
This is the standard way of inspect the response's content and will be more reliable than the previous implementation of trying to guess the content type based on the status code.
PR Checklist
Detailed Description of the Pull Request / Additional comments
Validation Steps Performed