better error handling issue #21

This commit is contained in:
Thomas Nahuel Rusiecki 2024-11-07 12:57:00 -03:00
parent e65dffe4d1
commit a47ca7978c
2 changed files with 18 additions and 6 deletions

View file

@ -37,8 +37,12 @@ class UploadForm(forms.Form):
if exist_annotation:
raise ValidationError("error: {} exist".format(file_name))
except Exception:
raise ValidationError("error in: {}".format(file_name))
except json.JSONDecodeError:
raise ValidationError("Error in parsing JSON: '{}'. Check for file integrity.".format(file_name))
except ValidationError as e:
raise e
except Exception as e:
raise ValidationError("Oops! Something went wrong in '{}': {}".format(file_name, str(e)))
self.evidences.append((file_name, file_json))

View file

@ -41,10 +41,18 @@ class Command(BaseCommand):
self.open(filepath)
def open(self, filepath):
with open(filepath, 'r') as file:
content = json.loads(file.read())
self.snapshots.append(content)
try:
with open(filepath, 'r') as file:
content = json.loads(file.read())
path_name = save_in_disk(content, self.user.institution.name)
self.snapshots.append((content, path_name))
except json.JSONDecodeError as e:
raise e
#or we cath'em all
except Exception:
raise Exception(f"Oops! Something went wrong there")
def parsing(self):
for s in self.snapshots:
self.devices.append(Build(s, self.user))