11import json
2+ import logging
23from circuits .api .serializers import CircuitSerializer , ProviderSerializer
34from dcim .api .serializers import (
45 LocationSerializer ,
1415from django .core .exceptions import ValidationError as DjangoValidationError
1516
1617
18+ logger = logging .getLogger (__name__ )
19+
20+
1721class SegmentSerializer (NetBoxModelSerializer ):
1822 """Default serializer Segment - now with file upload support"""
1923
@@ -100,9 +104,11 @@ def update(self, instance, validated_data):
100104 instance .save ()
101105
102106 except DjangoValidationError as e :
103- raise serializers .ValidationError (f"Path file error: { str (e )} " )
107+ logger .warning (f"Validation Path file error: { str (e )} " )
108+ raise serializers .ValidationError (f"Error processing file '{ path_file .name } '" )
104109 except Exception as e :
105- raise serializers .ValidationError (f"Error processing file '{ path_file .name } ': { str (e )} " )
110+ logger .error (f"Error processing file '{ path_file .name } ': { str (e )} " )
111+ raise serializers .ValidationError (f"Error processing file '{ path_file .name } '" )
106112
107113 return instance
108114
@@ -129,11 +135,13 @@ def create(self, validated_data):
129135 except DjangoValidationError as e :
130136 # Clean up created instance if path processing fails
131137 instance .delete ()
132- raise serializers .ValidationError (f"Path file error: { str (e )} " )
138+ logger .warning (f"Validation Path file error: { str (e )} " )
139+ raise serializers .ValidationError (f"Error processing file '{ path_file .name } '" )
133140 except Exception as e :
134141 # Clean up created instance if path processing fails
135142 instance .delete ()
136- raise serializers .ValidationError (f"Error processing file '{ path_file .name } ': { str (e )} " )
143+ logger .error (f"Error processing file '{ path_file .name } ': { str (e )} " )
144+ raise serializers .ValidationError (f"Error processing file '{ path_file .name } '" )
137145
138146 return instance
139147
0 commit comments