Skip to content

Conversation

@minhanh-phan
Copy link
Member

@minhanh-phan minhanh-phan commented Dec 18, 2025

Packages impacted by this PR

@azure/identity

Issues associated with this PR

Describe the problem that is addressed by this PR

  • In MSAL implementation of INetworkModule, the HttpClient will parse response with no body using parseBody and return an object with an error message. Our IdentityClient implementation returns an undefined body when response body is empty; thus raising Cannot read properties of undefined (reading 'expires_on') when MSAL handles the response. This PR aligns our behavior according to MSAL parseBody so that MSAL can surface the corresponding error. We also add additional logging for easier debugging when response body is empty

What are the possible designs available to address the problem? If there are more than one possible design, why was the one in this PR chosen?

Are there test cases added in this PR? (If not, why?)

Provide a list of related PRs (if any)

Command used to generate this PR:**(Applicable only to SDK release request PRs)

Checklists

  • Added impacted package name to the issue description
  • Does this PR needs any fixes in the SDK Generator?** (If so, create an Issue in the Autorest/typescript repository and link it here)
  • Added a changelog (if necessary)

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 PR fixes an issue where IdentityClient doesn't handle empty response bodies correctly when communicating with MSAL. It adds a new parseResponseBody method that gracefully handles JSON parsing failures and provides structured error information based on HTTP status codes.

Key Changes:

  • Added parseResponseBody method to handle empty/invalid response bodies and create error objects matching MSAL's expected format
  • Refactored response handling in sendGetRequestAsync and sendPostRequestAsync to use the new parsing method
  • Added comprehensive test coverage for both server (5xx) and client (4xx) error scenarios with empty bodies

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
sdk/identity/identity/src/client/identityClient.ts Adds parseResponseBody method to handle JSON parsing failures and generate structured error responses based on HTTP status codes
sdk/identity/identity/test/internal/node/managedIdentityCredential/msalMsiProvider.spec.ts Adds two new test cases verifying error handling for empty response bodies in server and client error scenarios
sdk/identity/identity/CHANGELOG.md Documents the bug fix for response format handling in empty response situations

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Untriaged

Development

Successfully merging this pull request may close these issues.

1 participant