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:
|
if exist_annotation:
|
||||||
raise ValidationError("error: {} exist".format(file_name))
|
raise ValidationError("error: {} exist".format(file_name))
|
||||||
|
|
||||||
except Exception:
|
except json.JSONDecodeError:
|
||||||
raise ValidationError("error in: {}".format(file_name))
|
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))
|
self.evidences.append((file_name, file_json))
|
||||||
|
|
||||||
|
|
|
@ -41,9 +41,17 @@ class Command(BaseCommand):
|
||||||
self.open(filepath)
|
self.open(filepath)
|
||||||
|
|
||||||
def open(self, filepath):
|
def open(self, filepath):
|
||||||
|
try:
|
||||||
with open(filepath, 'r') as file:
|
with open(filepath, 'r') as file:
|
||||||
content = json.loads(file.read())
|
content = json.loads(file.read())
|
||||||
self.snapshots.append(content)
|
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):
|
def parsing(self):
|
||||||
for s in self.snapshots:
|
for s in self.snapshots:
|
||||||
|
|
Loading…
Reference in New Issue