Skip to content

Commit

Permalink
fix: handled exception gracefully and returned proper response
Browse files Browse the repository at this point in the history
  • Loading branch information
abdullahwaheed committed Nov 25, 2024
1 parent d33974a commit 1c65627
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions commerce_coordinator/apps/frontend_app_ecommerce/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from edx_rest_framework_extensions.permissions import LoginRedirectIfUnauthenticated
from rest_framework.exceptions import PermissionDenied
from rest_framework.response import Response
from rest_framework.status import HTTP_303_SEE_OTHER
from rest_framework.status import HTTP_303_SEE_OTHER, HTTP_400_BAD_REQUEST
from rest_framework.throttling import UserRateThrottle
from rest_framework.views import APIView

Expand Down Expand Up @@ -94,18 +94,21 @@ def get(self, request):
if not request.user.lms_user_id: # pragma: no cover
raise PermissionDenied(detail="Could not detect LMS user id.")

order_data = OrderHistoryRequested.run_filter(request, params)
try:
order_data = OrderHistoryRequested.run_filter(request, params)

output_orders = []
output_orders = []

for order_set in order_data:
output_orders.extend(order_set['results'])
for order_set in order_data:
output_orders.extend(order_set['results'])

output = {
"count": request.query_params['page_size'], # This suppresses the ecomm mfe Order History Pagination ctrl
"next": None,
"previous": None,
"results": sorted(output_orders, key=lambda item: date_conv(item["date_placed"]), reverse=True)
}
output = {
"count": request.query_params['page_size'], # This suppresses the ecomm mfe Order History Pagination ctrl
"next": None,
"previous": None,
"results": sorted(output_orders, key=lambda item: date_conv(item["date_placed"]), reverse=True)
}

return Response(output)
return Response(output)
except Exception as exc:
return Response(status=HTTP_400_BAD_REQUEST, data=str(exc))

0 comments on commit 1c65627

Please sign in to comment.