Skip to content

Handle inventory errors and improve checkout process #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

seer-by-sentry[bot]
Copy link

Fixes REACT-5JE. The issue was that: Inventory check failed in process_order due to insufficient stock (initial stock 1), raising an unhandled exception causing a 500 error.

  • Added a custom InventoryError exception to handle out-of-stock situations with specific item IDs.
  • Modified process_order to raise InventoryError when insufficient inventory is available, including the requested and available quantities.
  • Updated the /checkout route to catch InventoryError and return a 400 error with a JSON response containing the error message and item ID.
  • Added more robust error handling in /checkout to catch generic exceptions, report them to Sentry, and return a 500 error.
  • Modified the inventory update logic to correctly decrement the inventory based on the quantity requested in the cart.
  • Added a copy of the Inventory object to avoid race conditions.

This fix was generated by Seer in Sentry, triggered by [email protected]. 👁️ Run ID: 112266

Not quite right? Click here to continue debugging with Seer.

return 'Success'
return jsonify(message="Order processed successfully"), 200
except InventoryError as ie:
return make_response(jsonify(error=str(ie), itemId=ie.item_id), 400)

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix

AI 10 days ago

To fix the issue, the error message returned to the user should be generic and avoid exposing internal application state. The detailed error message from the InventoryError exception can be logged for debugging purposes, but the response to the user should only indicate that there was an issue with their request.

The best way to implement this fix is to replace the str(ie) usage with a generic error message, such as "Insufficient inventory for the requested item." Additionally, the detailed error message can be logged using sentry_sdk.capture_exception(ie) or another logging mechanism.

Suggested changeset 1
app.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/app.py b/app.py
--- a/app.py
+++ b/app.py
@@ -87,3 +87,4 @@
     except InventoryError as ie:
-        return make_response(jsonify(error=str(ie), itemId=ie.item_id), 400)
+        sentry_sdk.capture_exception(ie)
+        return make_response(jsonify(error="Insufficient inventory for the requested item.", itemId=ie.item_id), 400)
     except Exception as e:
EOF
@@ -87,3 +87,4 @@
except InventoryError as ie:
return make_response(jsonify(error=str(ie), itemId=ie.item_id), 400)
sentry_sdk.capture_exception(ie)
return make_response(jsonify(error="Insufficient inventory for the requested item.", itemId=ie.item_id), 400)
except Exception as e:
Copilot is powered by AI and may make mistakes. Always verify output.
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.

0 participants