Catch error

This commit is contained in:
Oliver 2021-11-04 08:40:38 +11:00
parent 3a61d11f5a
commit 52242e7a00

View File

@ -62,7 +62,11 @@ class CategoryList(generics.ListCreateAPIView):
ctx = super().get_serializer_context()
ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()]
try:
ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()]
except AttributeError:
# Error is thrown if the view does not have an associated request
ctx['starred_categories'] = []
return ctx
@ -173,7 +177,11 @@ class CategoryDetail(generics.RetrieveUpdateDestroyAPIView):
ctx = super().get_serializer_context()
ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()]
try:
ctx['starred_categories'] = [star.category for star in self.request.user.starred_categories.all()]
except AttributeError:
# Error is thrown if the view does not have an associated request
ctx['starred_categories'] = []
return ctx