Skip to content

Conversation

NidhiDixit09
Copy link
Collaborator

Reference

EMT-2424 - https://branch.atlassian.net/browse/EMT-2424

Summary

Motivation

Type Of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Testing Instructions

cc @BranchMetrics/saas-sdk-devs for visibility.

Copy link
Contributor

Code Quality bug fix

Summary By MatterAI MatterAI logo

🔄 What Changed

This pull request refines the retry logic within the processRequest method. Previously, the system would only skip retries for specific error codes. Now, it explicitly includes all HTTP response codes in the 1xx (Informational), 2xx (Success), 3xx (Redirection), and 4xx (Client Error) ranges as conditions to skip further request processing and retries. A commented-out asynchronous block was also removed, indicating minor code cleanup.

🔍 Impact of the Change

This change significantly improves the efficiency and correctness of the request handling. By skipping retries for a broader range of HTTP response codes that typically indicate a final state (even client-side errors), it prevents unnecessary network calls and server load. This leads to more responsive application behavior and better resource utilization, especially in scenarios where client errors or successful operations might have previously triggered redundant retries.

📁 Total Files Changed

  • Sources/BranchSDK/Branch.m: Modified the processRequest method to update retry conditions and removed a commented-out code block.

🧪 Test Added

No explicit tests were added or modified in this pull request.

🔒Security Vulnerabilities

No new security vulnerabilities were introduced, and the change improves robustness by refining error handling.

Tip

Quality Recommendations

  1. Consider extracting the complex if condition into a private helper method (e.g., shouldSkipRetryForErrorCode:) to improve readability and maintainability of the processRequest method.

Tanka Poem ♫

Codes now understood,
One to four hundred, no retry.
Efficiency gained,
Network calls, a gentle breeze,
Logic refined, a clear path.

Sequence Diagram

sequenceDiagram
    participant Branch as Branch SDK
    participant Request as BNCServerRequest
    participant Response as BNCServerResponse
    participant Error as NSError

    Branch->>Branch: processRequest(req, response, error)
    activate Branch

    alt No Error or Specific Error Codes
        Branch->>Branch: Check if !error OR error.code is BNCTrackingDisabledError OR BNCBadRequestError OR BNCDuplicateResourceError
    and New Condition: HTTP 1xx-4xx
        Branch->>Branch: Check if (100 <= error.code <= 499)
    end

    alt Condition Met (Skip Retry)
        Branch->>Branch: BNCPerformBlockOnMainThreadSync(block)
        Branch->>Request: processResponse(response, error)
    else Condition Not Met (Potentially Retryable Error)
        Branch->>Branch: Handle other error codes (e.g., 5xx for retry)
    end
    deactivate Branch
Loading

Copy link
Contributor

Important

PR Review Skipped

PR review skipped as per the configuration setting. Run a manually review by commenting /matter review

💡Tips to use MatterAI

Command List

  • /matter summary: Generate AI Summary for the PR
  • /matter review: Generate AI Reviews for the latest commit in the PR
  • /matter review-full: Generate AI Reviews for the complete PR
  • /matter release-notes: Generate AI release-notes for the PR
  • /matter : Chat with your PR with MatterAI Agent
  • /matter remember : Generate AI memories for the PR
  • /matter explain: Get an explanation of the PR
  • /matter help: Show the list of available commands and documentation
  • Need help? Join our Discord server: https://discord.gg/fJU5DvanU3

@NidhiDixit09 NidhiDixit09 merged commit bb72ef8 into master Sep 9, 2025
15 checks passed
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