Skip to content

Commit

Permalink
feat: treat exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
helllllllder committed Oct 16, 2023
1 parent af87d11 commit 9b5779f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion chats/apps/api/v1/internal/projects/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def create(self, request, *args, **kwargs):

def put(
self, request, *args, **kwargs
): # TODO: GAMBIARRA ALERT! MOVE THIS LOGIC TO THE SERIALIZER
): # TODO: GAMBIARRA ALERT! MOVE THIS LOGIC TO THE SERIALIZER or somewhere else
qs = self.queryset
try:
user_email = request.data["user"]
Expand All @@ -87,6 +87,11 @@ def put(
},
status.HTTP_400_BAD_REQUEST,
)
except Project.DoesNotExist:
return Response(
{"Detail": f"The project {request.data['project']} does not exist yet"},
status.HTTP_404_NOT_FOUND,
)
return Response({"Detail": "Updated"}, status.HTTP_200_OK)

@action(detail=False, methods=["POST", "GET"], permission_classes=[IsAuthenticated])
Expand Down
4 changes: 2 additions & 2 deletions chats/apps/api/v1/quickmessages/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def get_queryset(self, *args, **kwargs):
try:
project = self.request.GET.get("project")
perm = self.request.user.project_permissions.get(project=project)
except (AttributeError, ObjectDoesNotExist):
except Exception as error:
raise exceptions.APIException(
detail="You don't have permission to access this project"
detail=f"You don't have permission to access this project. {type(error)}: {error}"
)
sectors = perm.get_sectors()
return QuickMessage.objects.all().filter(
Expand Down

0 comments on commit 9b5779f

Please sign in to comment.