From 693f353421c2acb7452d3e87f71d2245eca7a409 Mon Sep 17 00:00:00 2001 From: melanie c <66491435+melaniechen912@users.noreply.github.com> Date: Wed, 6 Mar 2024 22:47:32 -0500 Subject: [PATCH] Dedup APIError (#229) Co-authored-by: Justin Zhang --- backend/dining/api_wrapper.py | 5 +---- backend/gsr_booking/api_wrapper.py | 5 +---- backend/utils/errors.py | 2 ++ 3 files changed, 4 insertions(+), 8 deletions(-) create mode 100644 backend/utils/errors.py diff --git a/backend/dining/api_wrapper.py b/backend/dining/api_wrapper.py index 5fb85ddc..7965d370 100644 --- a/backend/dining/api_wrapper.py +++ b/backend/dining/api_wrapper.py @@ -7,16 +7,13 @@ from requests.exceptions import ConnectTimeout, ReadTimeout from dining.models import DiningItem, DiningMenu, DiningStation, Venue +from utils.errors import APIError OPEN_DATA_URL = "https://3scale-public-prod-open-data.apps.k8s.upenn.edu/api/v1/dining/" OPEN_DATA_ENDPOINTS = {"VENUES": OPEN_DATA_URL + "venues", "MENUS": OPEN_DATA_URL + "menus"} -class APIError(ValueError): - pass - - class DiningAPIWrapper: def __init__(self): self.token = None diff --git a/backend/gsr_booking/api_wrapper.py b/backend/gsr_booking/api_wrapper.py index 869d6add..bf291305 100644 --- a/backend/gsr_booking/api_wrapper.py +++ b/backend/gsr_booking/api_wrapper.py @@ -15,6 +15,7 @@ from gsr_booking.models import GSR, GroupMembership, GSRBooking, Reservation from gsr_booking.serializers import GSRBookingSerializer, GSRSerializer +from utils.errors import APIError User = get_user_model() @@ -38,10 +39,6 @@ class CreditType(Enum): ARB = "ARB" -class APIError(ValueError): - pass - - class AbstractBookingWrapper(ABC): @abstractmethod def book_room(self, rid, start, end, user): diff --git a/backend/utils/errors.py b/backend/utils/errors.py new file mode 100644 index 00000000..4e8609ac --- /dev/null +++ b/backend/utils/errors.py @@ -0,0 +1,2 @@ +class APIError(ValueError): + pass