Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: fix error response
Browse files Browse the repository at this point in the history
  • Loading branch information
aht007 committed Apr 18, 2023
1 parent b5cb314 commit 8b16fd0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
8 changes: 4 additions & 4 deletions ecommerce/bff/subscriptions/tests/test_subscription_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ def test_with_invalid_sku(self):
url = reverse('bff:subscriptions:product-entitlement-info')
response = self.client.get(url, data=[('sku', 1), ('sku', 2)])
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
expected_data = 'Products with SKU(s) [1, 2] do not exist.'
self.assertEqual(response.content.decode('utf-8'), expected_data)
expected_data = {'error': 'Products with SKU(s) [1, 2] do not exist.'}
self.assertCountEqual(json.loads(response.content.decode('utf-8')), expected_data)

def test_with_empty_sku(self):
url = reverse('bff:subscriptions:product-entitlement-info')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
expected_data = 'No SKUs provided.'
self.assertEqual(response.content.decode('utf-8'), expected_data)
expected_data = {'error': 'No SKUs provided.'}
self.assertCountEqual(json.loads(response.content.decode('utf-8')), expected_data)
5 changes: 2 additions & 3 deletions ecommerce/bff/subscriptions/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
from django.http import HttpResponseBadRequest
from django.utils.html import escape
from oscar.core.loading import get_model
from rest_framework import generics
from rest_framework import generics, status
from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response

from ecommerce.bff.subscriptions.permissions import CanGetProductEntitlementInfo
from ecommerce.bff.subscriptions.serializers import CourseEntitlementInfoSerializer
from ecommerce.extensions.api.exceptions import BadRequestException
from ecommerce.extensions.api.throttles import ServiceUserThrottle
from ecommerce.extensions.basket.exceptions import BadRequestException
from ecommerce.extensions.partner.shortcuts import get_partner_for_site

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -41,7 +40,7 @@ def get(self, request, *args, **kwargs):
"does not have a UUID attribute or mode is None")
return Response(data)
except BadRequestException as e:
return HttpResponseBadRequest(str(e))
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)

def _get_available_products(self, products):
unavailable_product_ids = []
Expand Down

0 comments on commit 8b16fd0

Please sign in to comment.