summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Friedli2020-08-21 12:00:39 +0200
committerjfriedli2020-09-06 08:29:17 -0700
commita768cf322726a3cbb56c5eda8958402dd34b012f (patch)
treeda9130a5f9aff548979421b7490b50aa999831d5
parente8bd56b5b4c596404e8d41e85f1029161ea4a63e (diff)
added basic logging
-rw-r--r--main.py2
-rw-r--r--matweb/rest_api.py15
2 files changed, 13 insertions, 4 deletions
diff --git a/main.py b/main.py
index 2fc23b1..ea027c7 100644
--- a/main.py
+++ b/main.py
@@ -57,7 +57,7 @@ def create_app(test_config=None):
57 Swagger(app, template=template, config=swagger_config) 57 Swagger(app, template=template, config=swagger_config)
58 58
59 CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}}) 59 CORS(app, resources={r"/api/*": {"origins": utils.get_allow_origin_header_value()}})
60 60 app.logger.info('Matweb started')
61 return app 61 return app
62 62
63 63
diff --git a/matweb/rest_api.py b/matweb/rest_api.py
index 50b7c37..72da1cd 100644
--- a/matweb/rest_api.py
+++ b/matweb/rest_api.py
@@ -30,22 +30,26 @@ class APIUpload(Resource):
30 args = req_parser.parse_args() 30 args = req_parser.parse_args()
31 try: 31 try:
32 file_data = base64.b64decode(args['file']) 32 file_data = base64.b64decode(args['file'])
33 except (binascii.Error, ValueError): 33 except (binascii.Error, ValueError) as e:
34 current_app.logger.error('Upload - Decoding base64 file %s', str(e))
34 abort(400, message='Failed decoding file') 35 abort(400, message='Failed decoding file')
35 36
36 file = FileStorage(stream=io.BytesIO(file_data), filename=args['file_name']) 37 file = FileStorage(stream=io.BytesIO(file_data), filename=args['file_name'])
37 try: 38 try:
38 filename, filepath = utils.save_file(file, current_app.config['UPLOAD_FOLDER']) 39 filename, filepath = utils.save_file(file, current_app.config['UPLOAD_FOLDER'])
39 except ValueError: 40 except ValueError:
41 current_app.logger.error('Upload - Invalid file name')
40 abort(400, message='Invalid Filename') 42 abort(400, message='Invalid Filename')
41 43
42 parser, mime = utils.get_file_parser(filepath) 44 parser, mime = utils.get_file_parser(filepath)
43 45
44 if parser is None: 46 if parser is None:
47 current_app.logger.error('Upload - Invalid mime type %s', mime)
45 abort(415, message='The type %s is not supported' % mime) 48 abort(415, message='The type %s is not supported' % mime)
46 49
47 meta = parser.get_meta() 50 meta = parser.get_meta()
48 if not parser.remove_all(): 51 if not parser.remove_all():
52 current_app.logger.error('Upload - Cleaning failed with mime: %s', mime)
49 abort(500, message='Unable to clean %s' % mime) 53 abort(500, message='Unable to clean %s' % mime)
50 54
51 key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER']) 55 key, secret, meta_after, output_filename = utils.cleanup(parser, filepath, current_app.config['UPLOAD_FOLDER'])
@@ -140,7 +144,9 @@ class APIBulkDownloadCreator(Resource):
140 data = request.json 144 data = request.json
141 if not data: 145 if not data:
142 abort(400, message="Post Body Required") 146 abort(400, message="Post Body Required")
147 current_app.logger.error('BulkDownload - Missing Post Body')
143 if not self.v.validate(data): 148 if not self.v.validate(data):
149 current_app.logger.error('BulkDownload - Missing Post Body: %s', str(self.v.errors))
144 abort(400, message=self.v.errors) 150 abort(400, message=self.v.errors)
145 # prevent the zip file from being overwritten 151 # prevent the zip file from being overwritten
146 zip_filename = 'files.' + str(uuid4()) + '.zip' 152 zip_filename = 'files.' + str(uuid4()) + '.zip'
@@ -157,16 +163,19 @@ class APIBulkDownloadCreator(Resource):
157 try: 163 try:
158 cleaned_files_zip.write(complete_path) 164 cleaned_files_zip.write(complete_path)
159 os.remove(complete_path) 165 os.remove(complete_path)
160 except ValueError: 166 except ValueError as e:
167 current_app.logger.error('BulkDownload - Creating archive failed: %s', str(e))
161 abort(400, message='Creating the archive failed') 168 abort(400, message='Creating the archive failed')
162 169
163 try: 170 try:
164 cleaned_files_zip.testzip() 171 cleaned_files_zip.testzip()
165 except ValueError as e: 172 except ValueError as e:
166 abort(400, message=str(e)) 173 current_app.logger.error('BulkDownload - Validating Zip failed: %s', str(e))
174 abort(400, message='Validating Zip failed')
167 175
168 parser, mime = utils.get_file_parser(zip_path) 176 parser, mime = utils.get_file_parser(zip_path)
169 if not parser.remove_all(): 177 if not parser.remove_all():
178 current_app.logger.error('BulkDownload - Unable to clean Zip')
170 abort(500, message='Unable to clean %s' % mime) 179 abort(500, message='Unable to clean %s' % mime)
171 key, secret, meta_after, output_filename = utils.cleanup(parser, zip_path, current_app.config['UPLOAD_FOLDER']) 180 key, secret, meta_after, output_filename = utils.cleanup(parser, zip_path, current_app.config['UPLOAD_FOLDER'])
172 return { 181 return {