Skip to content

Conversation

@avazirna
Copy link
Contributor

@avazirna avazirna commented Oct 20, 2025

Product Description

Backmerge CommCare 2.60

Summary by CodeRabbit

  • Bug Fixes

    • Improved error handling for HTTP client failures with enhanced error stream processing, logging, and error information capture for 4xx status responses.
  • Performance

    • Implemented response body caching for both successful and error responses, optimizing network request efficiency and reducing redundant processing.

@coderabbitai
Copy link

coderabbitai bot commented Oct 20, 2025

Walkthrough

HTTP error handling is enhanced by adding error response stream access. The HttpResponseProcessor.processClientError method signature now includes an InputStream errorStream parameter, supported by a new getErrorResponseStream() method in ResponseStreamAccessor. ModernHttpRequester implements response and error stream caching to support this capability.

Changes

Cohort / File(s) Summary
Interface Updates
src/main/java/org/commcare/core/interfaces/HttpResponseProcessor.java
Method signature updated: processClientError now accepts int responseCode and InputStream errorStream parameter for enhanced error handling
Stream Accessor Interface
src/main/java/org/commcare/core/interfaces/ResponseStreamAccessor.java
New public method added: @Nullable InputStream getErrorResponseStream() throws IOException to expose error response streams
HTTP Requester Implementation
src/main/java/org/commcare/core/network/ModernHttpRequester.java
Implements error stream access and caching: added getErrorResponseStream(Response) method, enhanced 4xx error handling to read and pass error streams to processor, implemented response body caching via cacheResponse, and extended ResponseStreamAccessor bridge with error stream access

Sequence Diagram

sequenceDiagram
    participant Client
    participant ModernHttpRequester
    participant HttpResponseProcessor
    participant ResponseCache

    Client->>ModernHttpRequester: HTTP Request (4xx response)
    ModernHttpRequester->>ResponseCache: cacheResponse(body)
    ResponseCache-->>ModernHttpRequester: cached InputStream
    
    alt Error stream present
        ModernHttpRequester->>ModernHttpRequester: getErrorResponseStream()
        ModernHttpRequester->>ResponseCache: cacheResponse(errorBody)
        ResponseCache-->>ModernHttpRequester: errorInputStream
        ModernHttpRequester->>HttpResponseProcessor: processClientError(responseCode, errorInputStream)
    else Error stream read fails
        ModernHttpRequester->>ModernHttpRequester: Log exception
        ModernHttpRequester->>HttpResponseProcessor: processClientError(responseCode, null)
    end
    
    HttpResponseProcessor-->>Client: Error handled
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

The changes involve interface signature updates requiring implementation consistency checks, new caching logic in ModernHttpRequester, stream resource management (proper closing/handling), and error path modifications. Complexity is moderate due to the spread across interface definitions and implementation details.

Possibly related PRs

Suggested reviewers

  • OrangeAndGreen
  • shubham1g5
  • Jignesh-dimagi

Poem

🐰 Streams flow like carrots fresh and new,
Error responses caught in cached view,
When four-oh-oh comes knocking at the door,
We read the error, share it more,
Processors happy, handlers gleam! 🌿

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 30.77% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Backmerge CommCare 2.60" is partially related to the changeset as it accurately describes the operation being performed—integrating changes from the CommCare 2.60 branch into master. However, the title does not convey the specific technical nature of the changes, which include updates to error response streaming, enhanced 4xx error handling in ModernHttpRequester, response body caching, and interface modifications to HttpResponseProcessor and ResponseStreamAccessor. While the title refers to a real aspect of what the PR accomplishes (the backmerge operation itself), it does not describe the main technical content of the actual code changes.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch commcare_2.60

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/main/java/org/commcare/core/network/ModernHttpRequester.java (1)

16-16: Unused import detected.

The StandardCharsets import doesn't appear to be used anywhere in this file.

Apply this diff to remove the unused import:

-import java.nio.charset.StandardCharsets;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2361d31 and d14fc42.

📒 Files selected for processing (3)
  • src/main/java/org/commcare/core/interfaces/HttpResponseProcessor.java (1 hunks)
  • src/main/java/org/commcare/core/interfaces/ResponseStreamAccessor.java (1 hunks)
  • src/main/java/org/commcare/core/network/ModernHttpRequester.java (4 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/main/java/org/commcare/core/network/ModernHttpRequester.java (1)
src/main/java/org/javarosa/core/services/Logger.java (1)
  • Logger (10-101)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: task-list-completed
🔇 Additional comments (6)
src/main/java/org/commcare/core/interfaces/ResponseStreamAccessor.java (1)

6-12: LGTM! Interface extension looks good.

The new getErrorResponseStream() method is appropriately annotated with @Nullable since error response streams may not always be available. The method signature is consistent with the existing getResponseStream() method.

src/main/java/org/commcare/core/network/ModernHttpRequester.java (4)

104-108: LGTM! Implementation follows established pattern.

The getErrorResponseStream() implementation correctly delegates to the requester's method and follows the same pattern as the existing getResponseStream() method.


186-194: Error stream handling looks solid.

The error handling logic properly:

  • Retrieves the error stream
  • Passes it to the processor
  • Logs any exceptions during error processing
  • Ensures the stream is closed via the finally block

The broad Exception catch on line 190 is acceptable here since this is error-path code where preventing crashes during error processing is more important than failing fast.


208-220: Excellent refactoring to eliminate duplication.

Extracting the cacheResponse method is a good improvement that allows both response and error streams to share the same caching logic, improving maintainability.


222-228: LGTM! Error response caching implemented correctly.

The method properly checks for a non-null error body before caching and correctly returns null otherwise, matching the @Nullable contract from the interface.

src/main/java/org/commcare/core/interfaces/HttpResponseProcessor.java (1)

23-23: Verify that external implementations of HttpResponseProcessor have been updated.

The breaking change to the HttpResponseProcessor interface has been applied (new InputStream errorStream parameter added), and the sole call site in this codebase (ModernHttpRequester.java:189) correctly uses the new 2-parameter signature. However, no implementing classes were found within this codebase. Since this interface appears to be consumed by external projects, ensure all downstream implementations outside this repository have been updated to match the new signature.

@avazirna avazirna merged commit 30aad9d into master Oct 24, 2025
2 of 3 checks passed
@avazirna
Copy link
Contributor Author

duplicate this PR 89841dc d14fc42

@avazirna
Copy link
Contributor Author

duplicate this PR 89841dc 42e31e0

@avazirna
Copy link
Contributor Author

duplicate this PR 89841dc 36d1726

@avazirna
Copy link
Contributor Author

duplicate this PR 89841dc 89841dc

@avazirna
Copy link
Contributor Author

duplicate this PR 36d1726 42e31e0

@avazirna
Copy link
Contributor Author

duplicate this PR 42e31e0 42e31e0

@shubham1g5
Copy link
Contributor

@avazirna Bdw I have a couple PRs here that should take care of this duplication already - #1506 and #1508

@avazirna
Copy link
Contributor Author

@avazirna Bdw I have a couple PRs here that should take care of this duplication already - #1506 and #1508

Hann, got it. I'm going to delete this branch then.

@avazirna avazirna deleted the commcare_2.60 branch October 28, 2025 11:18
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.

4 participants