Commit 686b721f authored by unknown's avatar unknown

final changes

parent 395e0cfd
Pipeline #3351 passed with stage
in 28 seconds
......@@ -15,6 +15,10 @@ from core.Guesser import Guesser
from logger.Logger import Logger
from File import File
from exceptions.parse_exception import ParseException
from exceptions.save_report_exception import SaveReportException
from exceptions.wrong_class_exception import WrongClassException
class Core:
"""
......@@ -58,20 +62,21 @@ class Core:
except Exception as f_e:
Logger.error.log(
'Error occurred while parsing file: {}'.format(f_e))
raise Exception('Invalid files')
raise ParseException('Corrupted files')
self.__choose_tool(form)
try:
self.__tool.parse()
except Exception as p_e:
Logger.error.log(
'Error occurred while parsing report: {}'.format(p_e))
raise Exception('Cannot parse report')
raise ParseException('Parsing tool was not successful')
try:
file.save_unified_report(
self.__tool.internal_structure.get(clear=True))
except Exception as f_e:
Logger.error.log('Error while creating json file: {}'.format(f_e))
raise SaveReportException('Error while saving report')
def __choose_tool(self, form) -> None:
"""
......@@ -90,9 +95,9 @@ class Core:
self.__tool = class_to_instantiate(
self.__bundled_source.get('report'))
except TypeError:
raise Exception('Cannot instantiate class')
raise WrongClassException('Cannot choose tool, please select tool manually')
if self.__tool is None:
raise Exception('Tool was not recognized')
raise WrongClassException('Cannot choose tool, please select tool manually')
def __register_tools(self) -> None:
"""
......
class ImportClassException(BaseException):
pass
\ No newline at end of file
class ParseException(BaseException):
pass
\ No newline at end of file
class SaveReportException(BaseException):
pass
\ No newline at end of file
class WrongClassException(BaseException):
pass
\ No newline at end of file
......@@ -7,7 +7,10 @@ import shutil
from flask import request, jsonify, make_response, json
from resources.v1.endpoints.BaseEndpoint import BaseEndpoint
from exceptions.wrong_class_exception import WrongClassException
from exceptions.import_class_exception import ImportClassException
from exceptions.parse_exception import ParseException
from exceptions.save_report_exception import SaveReportException
class Files(BaseEndpoint):
"""
......@@ -37,12 +40,11 @@ class Files(BaseEndpoint):
self.core.process_request(
uploaded_files=request.files, form=request.form)
return_bundle = self.core.export()
except NameError as ne:
except (WrongClassException, ImportClassException, ParseException, SaveReportException) as ne:
response = make_response(json.dumps({
'message': str(ne)
}), 503)
return response
except Exception:
response = make_response(json.dumps({
'message': 'Error while uploading files'
......@@ -132,7 +134,7 @@ class Files(BaseEndpoint):
try:
os.rename(old_folder, new_folder)
except Exception:
except:
response = make_response(json.dumps({
'message': 'rename was not successful'
}), 404)
......
......@@ -7,5 +7,5 @@ from setuptools import setup
setup(
name='backend',
version='0.2',
packages=['core', 'parse', 'resources', 'tests'],
packages=['core', 'parse', 'resources', 'tests', 'exceptions'],
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment