mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Catch potential file processing errors
This commit is contained in:
		| @@ -818,13 +818,22 @@ class BomExtractSerializer(serializers.Serializer): | |||||||
|             raise serializers.ValidationError(_("File is too large")) |             raise serializers.ValidationError(_("File is too large")) | ||||||
|  |  | ||||||
|         # Read file data into memory (bytes object) |         # Read file data into memory (bytes object) | ||||||
|  |         try: | ||||||
|             data = bom_file.read() |             data = bom_file.read() | ||||||
|  |         except Exception as e: | ||||||
|  |             raise serializers.ValidationError(str(e)) | ||||||
|  |  | ||||||
|         if ext in ['csv', 'tsv', 'xml']: |         if ext in ['csv', 'tsv', 'xml']: | ||||||
|  |             try: | ||||||
|                 data = data.decode() |                 data = data.decode() | ||||||
|  |             except Exception as e: | ||||||
|  |                 raise serializers.ValidationError(str(e)) | ||||||
|  |  | ||||||
|         # Convert to a tablib dataset (we expect headers) |         # Convert to a tablib dataset (we expect headers) | ||||||
|  |         try: | ||||||
|             self.dataset = tablib.Dataset().load(data, ext, headers=True) |             self.dataset = tablib.Dataset().load(data, ext, headers=True) | ||||||
|  |         except Exception as e: | ||||||
|  |             raise serializers.ValidationError(str(e)) | ||||||
|  |  | ||||||
|         for header in self.REQUIRED_COLUMNS: |         for header in self.REQUIRED_COLUMNS: | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user