Skip to content

Fix 500 - Internal Server Error in checkout flow (FRONTEND-REACT-6CS)#1387

Draft
cursor[bot] wants to merge 1 commit intomasterfrom
error-500---yr69rr
Draft

Fix 500 - Internal Server Error in checkout flow (FRONTEND-REACT-6CS)#1387
cursor[bot] wants to merge 1 commit intomasterfrom
error-500---yr69rr

Conversation

@cursor
Copy link

@cursor cursor bot commented Mar 25, 2026

Summary

Fixes FRONTEND-REACT-6CS: Resolves 500 Internal Server Error occurring during checkout submission.

Root Cause

The issue had two components:

  1. Backend (Flask): The quantities variable was accessed before being defined in the /checkout endpoint (line 225), causing a NameError that resulted in a 500 response
  2. Frontend (React): The error-checking logic was inverted (line 104), incorrectly throwing errors for valid HTTP error responses instead of only for network errors

Changes Made

Backend (flask/src/main.py)

  • Moved the quantities definition from line 228 to line 225
  • Now quantities = {int(k): v for k, v in cart['quantities'].items()} is executed before len(quantities) check

Frontend (react/src/components/CheckoutForm.jsx)

  • Fixed the inverted conditional logic in the error handling block
  • Changed from if (!response.error || response.status === undefined) to if (response.error)
  • Now correctly handles:
    • Network errors (when response.error exists) → capture to Sentry without throwing
    • HTTP errors (when response.error is undefined) → throw error to trigger navigation to error page

Testing

The fix ensures:

  • Backend no longer crashes when validating checkout inventory
  • Frontend correctly distinguishes between network errors and HTTP errors
  • Users are properly redirected to /error page on checkout failures
  • Appropriate Sentry events are captured for both error types
Open in Web Open in Cursor 

- Backend: Move quantities definition before usage in /checkout endpoint
- Frontend: Fix inverted error-checking logic in CheckoutForm.jsx
@vercel
Copy link
Contributor

vercel bot commented Mar 25, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
empower Ignored Ignored Mar 25, 2026 11:07pm

Request Review

@codecov
Copy link

codecov bot commented Mar 25, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 22.10%. Comparing base (4272cc5) to head (656d544).
✅ All tests successful. No failed tests found.

❌ Your project check has failed because the head coverage (22.10%) is below the target coverage (35.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1387      +/-   ##
==========================================
+ Coverage   22.01%   22.10%   +0.09%     
==========================================
  Files          42       42              
  Lines        1363     1357       -6     
  Branches      176      173       -3     
==========================================
  Hits          300      300              
+ Misses       1036     1030       -6     
  Partials       27       27              
Flag Coverage Δ *Carryforward flag
api 5.83% <ø> (+0.01%) ⬆️ Carriedforward from 4272cc5
frontend 32.56% <ø> (+0.19%) ⬆️ Carriedforward from 4272cc5

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
checkout_module 5.83% <ø> (+0.01%) ⬆️
product_component 26.26% <ø> (+0.23%) ⬆️
Files with missing lines Coverage Δ
flask/src/main.py 0.00% <ø> (ø)
react/src/components/CheckoutForm.jsx 16.66% <ø> (+0.73%) ⬆️

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