Skip to content

Comments

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
user/oneblue/json-parse
Open

Only try to parse into an ErrorResponse if the content-type is json#14241
OneBlue wants to merge 2 commits intofeature/wsl-for-appsfrom
user/oneblue/json-parse

Conversation

@OneBlue
Copy link
Collaborator

@OneBlue OneBlue commented Feb 20, 2026

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

  • Closes: Link to issue #xxx
  • Communication: I've discussed this with core contributors already. If work hasn't been agreed, this work might be rejected
  • Tests: Added/updated if needed and all pass
  • Localization: All end user facing strings can be localized
  • Dev docs: Added/updated if needed
  • Documentation updated: If checked, please file a pull request on our docs repo and link it here: #xxx

Detailed Description of the Pull Request / Additional comments

Validation Steps Performed

@OneBlue OneBlue requested a review from a team as a code owner February 20, 2026 21:16
Copilot AI review requested due to automatic review settings February 20, 2026 21:16
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 DockerHTTPException to 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() and InspectExec() methods to return typed objects instead of raw JSON strings, using the existing Transaction template 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()

Copy link
Member

@dkbennett dkbennett left a comment

Choose a reason for hiding this comment

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

Looks clean!

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