Skip to content
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

fix: handled exception gracefully and returned proper response #300

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 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,23 @@
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 = {
# This suppresses the ecomm mfe Order History Pagination control
"count": request.query_params['page_size'],
"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: # pylint: disable=broad-except
logger.error(f'UserOrdersView threw following exception: [{exc}]')
abdullahwaheed marked this conversation as resolved.
Show resolved Hide resolved
return Response(status=HTTP_400_BAD_REQUEST, data='Something went wrong!')

Check failure on line 116 in commerce_coordinator/apps/frontend_app_ecommerce/views.py

View workflow job for this annotation

GitHub Actions / tests (ubuntu-20.04, 3.8, django42)

Missing coverage

Missing coverage on lines 114-116
syedsajjadkazmii marked this conversation as resolved.
Show resolved Hide resolved
abdullahwaheed marked this conversation as resolved.
Show resolved Hide resolved
Loading