Commit 5f5421ca authored by Tom van Bussel's avatar Tom van Bussel
Browse files

Merge branch 'fix/flake8-bare-except-specific' into 'master'

Use more specific exceptions and include context

See merge request !618
parents e33e6550 34135e5c
...@@ -13,6 +13,7 @@ from rest_framework.permissions import ( ...@@ -13,6 +13,7 @@ from rest_framework.permissions import (
) )
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.viewsets import GenericViewSet from rest_framework.viewsets import GenericViewSet
from pytz.exceptions import InvalidTimeError
from events import services from events import services
from events.api.permissions import UnpublishedEventPermissions from events.api.permissions import UnpublishedEventPermissions
...@@ -34,8 +35,8 @@ def _extract_date_range(request): ...@@ -34,8 +35,8 @@ def _extract_date_range(request):
end = timezone.make_aware( end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d') datetime.strptime(request.query_params['end'], '%Y-%m-%d')
) )
except Exception: except (ValueError, KeyError, InvalidTimeError) as e:
raise ParseError(detail='start or end query parameters invalid') raise ParseError(detail='start or end query parameters invalid') from e
return end, start return end, start
......
...@@ -7,6 +7,7 @@ from rest_framework import viewsets, filters ...@@ -7,6 +7,7 @@ from rest_framework import viewsets, filters
from rest_framework.decorators import list_route from rest_framework.decorators import list_route
from rest_framework.exceptions import ParseError from rest_framework.exceptions import ParseError
from rest_framework.response import Response from rest_framework.response import Response
from pytz.exceptions import InvalidTimeError
from members.api.serializers import (MemberBirthdaySerializer, from members.api.serializers import (MemberBirthdaySerializer,
MemberRetrieveSerializer, MemberRetrieveSerializer,
...@@ -63,8 +64,9 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet): ...@@ -63,8 +64,9 @@ class MemberViewset(viewsets.ReadOnlyModelViewSet):
end = timezone.make_aware( end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d') datetime.strptime(request.query_params['end'], '%Y-%m-%d')
) )
except Exception: except (ValueError, KeyError, InvalidTimeError) as e:
raise ParseError(detail='start or end query parameters invalid') raise ParseError(
detail='start or end query parameters invalid') from e
queryset = ( queryset = (
Member.active_members Member.active_members
......
...@@ -7,6 +7,7 @@ from rest_framework.exceptions import ParseError ...@@ -7,6 +7,7 @@ from rest_framework.exceptions import ParseError
from rest_framework.permissions import IsAuthenticatedOrReadOnly, \ from rest_framework.permissions import IsAuthenticatedOrReadOnly, \
IsAuthenticated IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
from pytz.exceptions import InvalidTimeError
from partners.api.serializers import PartnerEventCalendarJSSerializer, \ from partners.api.serializers import PartnerEventCalendarJSSerializer, \
PartnerEventSerializer, PartnerSerializer PartnerEventSerializer, PartnerSerializer
...@@ -21,8 +22,8 @@ def _extract_date_range(request): ...@@ -21,8 +22,8 @@ def _extract_date_range(request):
end = timezone.make_aware( end = timezone.make_aware(
datetime.strptime(request.query_params['end'], '%Y-%m-%d') datetime.strptime(request.query_params['end'], '%Y-%m-%d')
) )
except Exception: except (ValueError, KeyError, InvalidTimeError) as e:
raise ParseError(detail='start or end query parameters invalid') raise ParseError(detail='start or end query parameters invalid') from e
return end, start 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