Fix inverted error handling logic in CheckoutForm (FRONTEND-REACT-6DK)#1423
Draft
cursor[bot] wants to merge 1 commit intomasterfrom
Draft
Fix inverted error handling logic in CheckoutForm (FRONTEND-REACT-6DK)#1423cursor[bot] wants to merge 1 commit intomasterfrom
cursor[bot] wants to merge 1 commit intomasterfrom
Conversation
Fixes FRONTEND-REACT-6DK The checkout function was incorrectly throwing a new Error for valid HTTP error responses (like 500) due to inverted logic. The condition '!response.error || response.status === undefined' would be true for normal HTTP error responses since response.error is undefined in those cases (fetch only sets response.error for network failures). This caused the frontend to throw an unnecessary error on top of backend errors, triggering the error page navigation when it shouldn't. Fixed by removing the throw statement from the else block, so valid HTTP error responses are tracked in metrics but don't cause a new error to be thrown. Network errors are still properly captured via Sentry.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes FRONTEND-REACT-6DK - Resolves incorrect error throwing for valid HTTP 500 responses in the checkout form.
Problem
The checkout function in
CheckoutForm.jsxhad inverted conditional logic that caused it to throw a new Error for valid HTTP error responses (like 500 status codes). This happened because:fetch()receives an HTTP 500 response, it returns a Response object withok: falseandstatus: 500response.errorproperty isundefinedfor HTTP responses (it's only set by the custom.catch()handler for network errors)!response.error || response.status === undefinedevaluated totruefor HTTP errorsSolution
Removed the
throw new Error()statement from the else block that handles valid HTTP error responses. Now the code:response.errorexists): Properly captured via SentryThis prevents the frontend from incorrectly navigating to the error page when the backend returns expected error responses like inventory validation failures.
Changes
checkout()function to only capture errors for network failuresTesting
The fix ensures that when the backend returns an HTTP 500 due to inventory validation failure, the frontend will: