From 9a84273e800d38f99649891844fcc85a09666ebe Mon Sep 17 00:00:00 2001 From: Ernesto Rico Schmidt <ernesto@helsinki.at> Date: Wed, 11 Sep 2024 15:58:11 -0400 Subject: [PATCH] feat: handle exception while converting date from iso format --- program/views.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/program/views.py b/program/views.py index b740b9ea..1c00187c 100644 --- a/program/views.py +++ b/program/views.py @@ -1138,8 +1138,12 @@ class APIScheduleViewSet(viewsets.ModelViewSet): # "clear" the last_date if the field has no value schedule.last_date = None else: - last_date = date.fromisoformat(last_date) + try: + last_date = date.fromisoformat(last_date) + except ValueError as e: + data = {"last_date": e.args[0]} + return Response(data, status=status.HTTP_400_BAD_REQUEST) if schedule.last_date is None or schedule.last_date > last_date: schedule.last_date = last_date -- GitLab