Skip to content

Commit

Permalink
chore(fix): fix for production
Browse files Browse the repository at this point in the history
  • Loading branch information
ndu committed Dec 12, 2024
1 parent ade71dd commit c8d4df8
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions server/apps/research/serializers/article_serializer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from rest_framework import serializers
from django.db import transaction
import logging
from django.conf import settings
from django.core.exceptions import ValidationError as DjangoValidationError
from ..models import Article, Author, Category, RelatedArticle
from .author_serializer import AuthorSerializer
Expand Down Expand Up @@ -32,7 +33,11 @@ def _handle_error(self, error, operation_type, context_data):
Centralized error handling for article operations
"""
if isinstance(error, DjangoValidationError):
raise serializers.ValidationError(error.message_dict) from error
if settings.DEBUG:
raise serializers.ValidationError(error.message_dict) from error
raise serializers.ValidationError({
"non_field_errors": ["Invalid data provided."]
}) from error

logger.error(
f"Error {operation_type} article",
Expand Down Expand Up @@ -148,7 +153,7 @@ def _handle_relations(self, article, authors, categories, related_article_ids):
},
exc_info=True
)
raise serializers.ValidationError(f"Related object not found: {str(e)}") from e
raise serializers.ValidationError("Related object not found") from e

except Exception as e:
logger.error(
Expand All @@ -162,7 +167,7 @@ def _handle_relations(self, article, authors, categories, related_article_ids):
},
exc_info=True
)
raise serializers.ValidationError("Error setting related objects") from e
raise serializers.ValidationError("An error occurred while setting related objects") from e

def create(self, validated_data):
"""Create a new Article instance."""
Expand Down

0 comments on commit c8d4df8

Please sign in to comment.