better error handling issue #21
This commit is contained in:
parent
e65dffe4d1
commit
a47ca7978c
|
@ -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))
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue