Use more specific exceptions and include context

parent e33e6550
......@@ -13,6 +13,7 @@ from rest_framework.permissions import (
)
from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet
from pytz.exceptions import InvalidTimeError
from events import services
from events.api.permissions import UnpublishedEventPermissions
......@@ -34,8 +35,8 @@ def _extract_date_range(request):
end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d')
)
except Exception:
raise ParseError(detail='start or end query parameters invalid')
except (ValueError, KeyError, InvalidTimeError) as e:
raise ParseError(detail='start or end query parameters invalid') from e
return end, start
......
......@@ -7,6 +7,7 @@ from rest_framework import viewsets, filters
from rest_framework.decorators import list_route
from rest_framework.exceptions import ParseError
from rest_framework.response import Response
from pytz.exceptions import InvalidTimeError
from members.api.serializers import (MemberBirthdaySerializer,
MemberRetrieveSerializer,
......@@ -63,8 +64,9 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d')
)
except Exception:
raise ParseError(detail='start or end query parameters invalid')
except (ValueError, KeyError, InvalidTimeError) as e:
raise ParseError(
detail='start or end query parameters invalid') from e
queryset = (
Member.active_members
......
......@@ -7,6 +7,7 @@ from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAuthenticatedOrReadOnly, \
IsAuthenticated
from rest_framework.response import Response
from pytz.exceptions import InvalidTimeError
from partners.api.serializers import PartnerEventCalendarJSSerializer, \
PartnerEventSerializer, PartnerSerializer
......@@ -21,8 +22,8 @@ def _extract_date_range(request):
end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d')
)
except Exception:
raise ParseError(detail='start or end query parameters invalid')
except (ValueError, KeyError, InvalidTimeError) as e:
raise ParseError(detail='start or end query parameters invalid') from e
return end, start
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment