diff --git a/server/apps/research/views.py b/server/apps/research/views.py index 3e4f174..1667139 100644 --- a/server/apps/research/views.py +++ b/server/apps/research/views.py @@ -43,6 +43,8 @@ def create(self, request, *args, **kwargs): return Response(serializer.data, status=status.HTTP_201_CREATED) except Exception as e: logger.error(f"Unexpected error during article creation: {e}") + if isinstance(e, serializers.ValidationError): + return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) return Response({'error': 'Failed to create a new Article'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) def update(self, request, *args, **kwargs): @@ -53,8 +55,10 @@ def update(self, request, *args, **kwargs): serializer.is_valid(raise_exception=True) self.perform_update(serializer) return Response(serializer.data, status=status.HTTP_200_OK) - except Exception as e: + except Exception as e: logger.error(f"Unexpected error during article update: {e}") + if isinstance(e, serializers.ValidationError): + return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST) return Response({'error': 'Error updating article'}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) # Custom action to retrieve articles by slug or UUID