Skip to content

Conversation

@armando-rodriguez-cko
Copy link
Contributor

Fix: Handle NoContent and null response in DeserializeResponseAsync

Key Changes

This PR enhances the DeserializeResponseAsync method in ApiClient to handle cases where the HTTP response has no content (204 No Content) or when httpResponse.Content is null. It prevents potential exceptions when accessing ContentLength on a null content.

Changes

  • Added a null check for httpResponse.Content before accessing ContentLength.
  • Ensured that DeserializeResponseAsync correctly returns an empty instance for 204 No Content responses.
  • Updated unit tests to validate the new behaviour.

Why is this needed?

Previously, if the response was 204 No Content or had null content, DeserializeResponseAsync could throw a NullReferenceException. This fix improves stability and ensures graceful handling of such cases.

@armando-rodriguez-cko armando-rodriguez-cko requested a review from a team March 14, 2025 12:38
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the bugfix/fix-handle-no-content-and-null-response branch 3 times, most recently from e5da261 to ba48c90 Compare March 14, 2025 13:03
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the bugfix/fix-handle-no-content-and-null-response branch 3 times, most recently from 601ae9a to 7eacd64 Compare March 17, 2025 11:33
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the bugfix/fix-handle-no-content-and-null-response branch from 7eacd64 to 5660320 Compare March 17, 2025 12:00
@armando-rodriguez-cko armando-rodriguez-cko force-pushed the bugfix/fix-handle-no-content-and-null-response branch from 5660320 to a2e76ea Compare March 17, 2025 13:34
@armando-rodriguez-cko armando-rodriguez-cko merged commit 365c237 into master Mar 17, 2025
5 checks passed
@armando-rodriguez-cko armando-rodriguez-cko deleted the bugfix/fix-handle-no-content-and-null-response branch March 17, 2025 14:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants