Skip to content

Fix hardcoded exception in processDeliveryItem method#206

Draft
cursor[bot] wants to merge 1 commit intomainfrom
mainfragmentbackendapiexception-failed-to-mamtug
Draft

Fix hardcoded exception in processDeliveryItem method#206
cursor[bot] wants to merge 1 commit intomainfrom
mainfragmentbackendapiexception-failed-to-mamtug

Conversation

@cursor
Copy link
Copy Markdown

@cursor cursor bot commented Mar 31, 2026

Summary

Fixes ANDROID-DN

This PR resolves the issue where a hardcoded MainFragment$BackendAPIException was being thrown in the processDeliveryItem() method when the checkout API fails.

Problem

When the Android app's checkout flow encounters an HTTP 500 error (e.g., due to backend inventory validation failures), the app enters the failure handling path and calls processDeliveryItem(). However, instead of properly handling the delivery workflow initialization, the method was deliberately throwing a hardcoded exception on line 427.

Root Cause Flow:

  1. User clicks cart button in Android app
  2. User selects items and proceeds to checkout
  3. App requests checkout via POST to /checkout endpoint
  4. Backend rejects with HTTP 500 due to inventory validation failure
  5. Android app calls processDeliveryItem() which throws hardcoded exception
  6. This causes unnecessary BackendAPIException to be thrown

Solution

Removed the deliberate throw statement and replaced it with proper error handling:

  • Logs a warning that checkout failed and delivery workflow cannot be initialized
  • Sets the span status to INTERNAL_ERROR appropriately
  • Completes without throwing an unnecessary exception
  • Still captures any genuine exceptions that may occur in the catch block

Changes

Modified app/src/main/java/com/example/vu/android/empowerplant/MainFragment.java:

  • Line 427: Removed throw new MainFragment.BackendAPIException("Failed to init delivery workflow");
  • Added proper logging and error handling instead

Testing

The fix ensures that when checkout fails:

  • The error is properly logged with appropriate severity
  • Sentry tracking continues to work correctly (span status is set to INTERNAL_ERROR)
  • The app doesn't crash with an unnecessary hardcoded exception
  • The checkout transaction properly finishes with INTERNAL_ERROR status
Open in Web Open in Cursor 

Fixes ANDROID-DN

Removed the deliberate throw statement on line 427 that was causing
MainFragment$BackendAPIException when checkout HTTP response fails.

The processDeliveryItem() method is called on failed checkout responses
to handle delivery workflow initialization. Previously, it immediately
threw a hardcoded exception instead of properly handling the failure case.

Now the method:
- Logs a warning that checkout failed and delivery workflow cannot be initialized
- Sets the span status to INTERNAL_ERROR appropriately
- Completes without throwing an unnecessary exception
- Still captures any genuine exceptions that may occur

This allows the Android app to gracefully handle HTTP 500 errors from
the backend (e.g., due to inventory validation failures) without
crashing with a hardcoded exception.
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (814e302) to head (c831d83).

Files with missing lines Patch % Lines
.../example/vu/android/empowerplant/MainFragment.java 0.00% 2 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #206   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         16      16           
  Lines        864     866    +2     
  Branches      65      65           
=====================================
- Misses       864     866    +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant