From 5524422d5ed43e0a2db7e71e05ce11fa917f407a Mon Sep 17 00:00:00 2001 From: Justin Zhang Date: Sun, 10 Sep 2023 12:45:55 -0400 Subject: [PATCH 1/2] Add APIError catch --- backend/dining/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/backend/dining/views.py b/backend/dining/views.py index 78939afd..7d46b150 100644 --- a/backend/dining/views.py +++ b/backend/dining/views.py @@ -9,7 +9,7 @@ from rest_framework.response import Response from rest_framework.views import APIView -from dining.api_wrapper import DiningAPIWrapper +from dining.api_wrapper import DiningAPIWrapper, APIError from dining.models import DiningMenu, Venue from dining.serializers import DiningMenuSerializer @@ -23,8 +23,10 @@ class Venues(APIView): """ def get(self, request): - return Response(d.get_venues()) - + try: + return Response(d.get_venues()) + except APIError as e: + return Response({"error": str(e)}, status=400) class Menus(generics.ListAPIView): """ From 5e419b8b39050c0852ae941541f0e71be449356f Mon Sep 17 00:00:00 2001 From: Justin Zhang Date: Sun, 10 Sep 2023 12:50:19 -0400 Subject: [PATCH 2/2] Lint --- backend/dining/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/dining/views.py b/backend/dining/views.py index 7d46b150..552e751c 100644 --- a/backend/dining/views.py +++ b/backend/dining/views.py @@ -9,7 +9,7 @@ from rest_framework.response import Response from rest_framework.views import APIView -from dining.api_wrapper import DiningAPIWrapper, APIError +from dining.api_wrapper import APIError, DiningAPIWrapper from dining.models import DiningMenu, Venue from dining.serializers import DiningMenuSerializer @@ -28,6 +28,7 @@ def get(self, request): except APIError as e: return Response({"error": str(e)}, status=400) + class Menus(generics.ListAPIView): """ GET: returns list of menus, defaulted to all objects within the week,